Programming
Programming
We seek to create and develop Vibrant, Skilled, Competent and Work-prepared Entrepreneurial Technicians, Technologists and
Professionals for the industry and the national economic vitality.
Main Examination
2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104:
Principles of Programming
Instructions to Students
1. Do not begin this exam until your invigilator instructs you to do so.
2. Write only in Black or Blue ink. Answer papers written in pencil will NOT be marked
3. All answers must be written in the answer booklet provided
4. Read each question carefully before you start to answer it.
Part A: Multiples choice
a) #include [userdefined]
b) #include “userdefined”
c) #include < iostream >
d) #include <userdefined>
a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */
a) ||
b) |
c) &
d) &&
a) Outputs Hello
b) Error
c) Outputs Hello twice
d) Error in the main function
#include <iostream>
using namespace std;
int main()
{
string s = "spaces in text";
cout << s << endl;
}
a) spacesintext
b) spaces in text
c) spaces
d) spaces in
#include <iostream>
using namespace std;
int main()
{
int p;
int p2;
int p1 = 2;
bool a = true;
bool b = false;
int x = 10;
int y = 5;
p2 = ((x | y) + (a + b));
cout << p;
return 0;
}
a) 12
b) 0
c) 2
d) 16
int main()
{
register int i = 1;
int *ptr = &i;
cout << *ptr;
return 0;
}
a)Runtime error may be possible
b) Compiler error may be possible
c) 1
d) 0
a) 1 bits
b) 2 bits
c) 3 bits
d) 4 bits
10) Which concept allows you to reuse the written code? [2 Marks]
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
Computational thinking is the step that comes before programming. It’s the
process of breaking down a problem into simple enough steps that even a
computer would understand. We all know that computers take instructions
very literally, sometimes to comic results.
Decomposition
breaking down a complex problem or system into smaller, more
manageable parts
Pattern recognition
looking for similarities among and within problems.
Abstraction
focusing on the important information only, ignoring irrelevant detail.
Algorithms
developing a step-by-step solution to the problem, or the rules to follow
to solve the problem
Efficiency/performance
The system resources consumed by the program, CPU cycles,
processor time, memory space, accessing storage media
Maintainability
Ease with which a program can be modified by its present or future
developer in order to carry out corrective, perfective or adaptive
maintenance
Portability
Range of computer hardware, operating systems and platforms on
which the source code can be run/compiled/interpreted
Reliability
Accuracy and the consistency of its outputs
Robustness
Quality of coding and testing to ensure that extreme and erroneous
data can be processed without causing the program to crash
Usability
Ease with which an end user can use the program.
include <iostream>
using namespace std;
int i=10;
8. Create a program to show functions that adds two numbers and print out the
summation. [10 Marks]
a. Header files.
b. Main methods.
c. Member functions.
d. Please comment.
include <iostream>
using namespace std;
void sum(int x, int y) {
int z;
z = x + y;
int main()
{
int a = 10;
int b = 20;
sum (a, b);
}
9. Create a program to show functions that multiple three numbers and print out
the product. [10 Marks]
a. Header files.
b. Main methods.
c. Member functions.
d. Please comment.
include <iostream>
using namespace std;
void multi(int x, int y, int z) {
int z;
z = x * y * z;
cout << z;
}
int main()
{
int a = 10;
int b = 20;
int b = 30
sum (a, b,c);
}