CIT-3153-OBJECT-ORIENTED-PROGRAMMING-I
CIT-3153-OBJECT-ORIENTED-PROGRAMMING-I
a) State and explain three access modifiers used in C++ programming. (6 Marks)
b) With the aid of a diagram, explain the difference between multiple inheritance and hierarchical
inheritance. (4 Marks)
c) Write a function that takes one integer arguments n, then uses recursion to compute and return
the value of n!.ie n factorial. (5 Marks)
d) Write a C++ program segment that defines a class called Rectangle with two private data
members length and width and a method getValues for retrieving the data members.
(5 Marks)
QUESTION THREE (20 MARKS)
a) Explain why and when a programmer may use protected instead of private access specifier
while defining a class. (2 Marks)
b) Write a C++ program that implements an array that reads in five elements then find the sum
average of the elements. (6 Marks)
c) Write C++ statements to do the following:
i. Open the file named cbet,dat using the variable outfile. (2 Marks)
ii. Write the values of the variables regno,sname, and score in the file cbet.dat.
(2 Marks)
d) The scope of an identifier is that part of the C++ program in which the identifier is accessible.
Briefly discuss the four types of scope in C++. (8 Marks)
a) State two conditions that are necessary for a function to be recursive. (2 Marks)
b) Distinguish between the following terms as used in programming. (6 Marks)
i. Function overloading and function overriding
ii. Base class and derived class
iii. Constructor and destructor
c) Write a C++ program that takes any two integer numbers (between 2 and 9) as input; then using
iteration statements, display all the multiples of either of the two numbers between 1 and 100,
while skipping the multiple of both of the numbers. Eg. If the user enters number 3 and number 4,
the output will be; 3,4,6,8,9,15,16,18,20,21,27(Skip 12,24,36… since these are multiples of both
of 3 and 4). (6 Marks)
d) Write separate statements in C+++ to achieve each of the following;