Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

National Institute of Technology

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.

School of Applied Engineering,


Innovation and Technology
Certificate in Network/Software Engineering
(Level 4)

Main Examination
2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104:
Principles of Programming

Date: 10 July 2022

Total marks: __/100


Assessor: Mr David Mutenda Moderator: Mr. Andreas Itana

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

1) What is C++? [2 Marks]

a) C++ is an object oriented programming language


b) C++ is a procedural programming language only
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language

2) Which is the correct syntax of including header files in C++? [2 Marks]

a) #include [userdefined]
b) #include “userdefined”
c) #include < iostream >
d) #include <userdefined>

3) Which of the following is used for comments in C++? [2 Marks]

a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */

4) Identify the logical AND operator. [2 Marks]

a) ||
b) |
c) &
d) &&

5) What happens if the following program is executed C++? [2 Marks]

#include <iostream >


void func()
{
cout<<"Hello";
}
int main()
{
func();
}

a) Outputs Hello
b) Error
c) Outputs Hello twice
d) Error in the main function

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 2|Page


6) What will be the output of the following code? [2 Marks]

#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

7) What is the value of p in the following C++ code snippet? [2 Marks]

#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

8) What will be the output of the following function? [2 Marks]

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

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 3|Page


9) What is the sizeof char? [2 Marks]

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

--- END OF PART A ---

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 4|Page


Part B: Short Questions

1. Discuss your understanding of what is a programming language? [6 Marks]

A programming language is a vocabulary and set of grammatical rules for


instructing a computer or computing device to perform specific tasks.

2. Justify computational thinking and the techniques involved? [6 Marks]

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

3. Discuss the uses of Software Applications? [5 Marks]

Gaming and entertainment


Productivity
Information storage and management
Repetitive tasks or dangerous tasks
Social media
Search engines

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 5|Page


4. Present all the Software Applications Qualities? [10 Marks]

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.

5. Demonstrate the steps of Software Development Life Cycle [15 Marks]

Assessment of the requirements for an identified problem


Design specification
Develop code
Implementation
Test
Validation
Refinement
Optimization
Maintenance

6. Illustrate what is a variable and discuss the types of variable? [8 Marks]

Is a name given to a specific memory location that is reserved to store/keep a


value from a specific data type? The values kept in a variable may change
during program execution.

7. Create a program to show your understanding of global and local variable.


[10 Marks]
a. Header files.
b. Main methods.
c. Member functions.
d. Please comment.

include <iostream>
using namespace std;

int x; // Global variable declare

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 6|Page


int main()
{

int i=10;

if(i<20) // if condition scope starts


{
int n = 100; // Local variable declared and initialized
} // if condition scope ends

cout << n // Compile time error, n not available here

x=10; // Initialized once

cout <<"first value of x = "<< x;


x=20; // Initialized again 19
cout <<"Initialized again with value = "<< x;
}

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;

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 7|Page


cout << z;
}

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);
}

--- END OF PART B ---

2ITCS104/2INE104/2ITSE104/2CE103/2ME104/2EEE104: Principles of Programming 8|Page

You might also like