Vous êtes sur la page 1sur 3

DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY

UNIVERSITY EXAMINATIONS 2017/2018

MODULE III EXAMINATION FOR THE DEGREE OF BACHELOR OF


ENGINERING IN MECHANICAL ENGINEERING (TVET)

ICS 2276: COMPUTER PROGRAMMING II

DATE: 13th APRIL 2018 TIME: 11-1PM

Instructions: Answer Question 1 and Any Other two.

Question One (30 marks)


(a) Define a C ++ computer program (2 Marks)
(b) Write a C++ program that will give the following output to the screen (2 marks)
Hello World.
My name is Harry.
(c) Explain the uses following tools in C++ programming (4 marks)
i. Text editor
ii. Compiler
iii. Interpreter
iv. Debugger
(d) Explain any TWO programming errors that a C++ programmer may encounter in the
course of developing programs (4 Marks)

(e) Write a C++ program to calculate the area of a rectangle (4 Marks)

(f) Using diagrams, differentiate between compilation and interpretation in C++


programming (4 marks)

(g) Using examples, Differentiate between assignment and equal operators in C ++.
(4 marks)

(h) Name two types of comments in C++ programming? Why are comments important?
(3 marks)

(i) It is very difficult to master and use machine language in programming. State two
scenarios when it is advisable to use a machine language over high level language and
why? (3 marks)

Page 1 of 3
Question Two (20 marks).
(a) Write a c++ program to calculate the KCSE average marks of a student for the
three compulsory subjects i.e. Mathematics, English and Kiswahili (7 Marks)
(b) Explain the output of the following C++ code snippet. (4 Marks)
int x, m, n;
m = 10;
n = 15;
x = ++m + n++;
cout<<”The values of m,n,x
are:”<<m”,”<<n”,”<<x<<”respectively.”<<endl;
(c) Write a C++ program find the area and the perimeter of a rectangle respectively.
(6 Marks)
(d) What is the first and the final values of i output by this loop. Explain
(3 Marks)

n=10;i=0; while (++i<n){


Cout<<i<<endl;

Question Three (20 marks)


a) Outline any FOUR C++ supported data types (4 Marks)
b) Write a program to read three numbers and print the least of the given three
numbers (4 Marks)
c) Using for loop, write a C++ program to print numbers from 1 to 10 in a horizontal
line (4 marks)
d) Modify the program above to print numbers 1 to 10 using while loop(4 marks)
e) Using a for…statement, write a C++ program that would give the following output
on the screen. (4mks)

1,2,3,5,6,7

Question Four (20 marks)


a) Explain the following as used in C++ programming (4 marks)
i. Object
ii. Class
iii. Methods
iv. Variables

b) Using relevant diagrams, discuss the two main differences between the while and
the do…while structures. (4 Marks)

Page 2 of 3
Your lecturer for Programming II has recorded percentage marks for six students in
four continuous assessment tests as shown in the table below.

CA 1 CAT 2 CAT 3 CAT 4


KIBET 90 34 76 45
OWOUR 55 56 70 67
MWENDA 45 78 70 89
MUSYOKA 89 65 56 90
MWANGI 67 56 72 76
ATIENO 70 90 68 56

i) Write a C++ statement that would create a data type to store the above
values.
(2Marks)
ii) Write a C++ nprogram that would initialize the above values dynamically
and calculate the total mark and average score for each student.
(10 Marks)

Page 3 of 3

Vous aimerez peut-être aussi