0% found this document useful (0 votes)
38 views

CIT-3153-OBJECT-ORIENTED-PROGRAMMING-I

This document outlines the examination details for various degree programs at Meru University of Science and Technology for the course CIT 3153: Object-Oriented Programming I. It includes instructions for the exam, a series of questions covering key concepts in C++ programming, including class definitions, access specifiers, recursion, and file handling. The exam consists of five questions, with a requirement to answer Question One and any two additional questions.

Uploaded by

mwitasimion
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

CIT-3153-OBJECT-ORIENTED-PROGRAMMING-I

This document outlines the examination details for various degree programs at Meru University of Science and Technology for the course CIT 3153: Object-Oriented Programming I. It includes instructions for the exam, a series of questions covering key concepts in C++ programming, including class definitions, access specifiers, recursion, and file handling. The exam consists of five questions, with a requirement to answer Question One and any two additional questions.

Uploaded by

mwitasimion
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MERU UNIVERSITY OF SCIENCE AND TECHNOLOGY

P.O. Box 972-60200 – Meru-Kenya.


Tel: +254(0) 799 529 958, +254(0) 799 529 959, +254 (0)712 524 293
Website: www.must.ac.ke Email: [email protected]

UNIVERSITY EXAMINATIONS 2022/2023

FIRST YEAR, SECOND SEMESTER EXAMINATION FOR THE DEGREE OF BACHELOR


OF DATA SCIENCE, BACHELOR OF COMPUTER SCIENCE, BACHELOR OF
COMPUTER SECURITY AND FORENSICS, BACHELOR OF MATHEMATICS AND
COMPUTER SCIENCE AND BACHELOR OF SCIENCE IN SYSTEM MANAGEMENT,
BACHELOR OF SCIENCE IN EDUCATION ARTS AND BACHELOR OF SCIENCE IN
STATISTICS
AND
SECOND YEAR, SECOND SEMESTER EXAMINATION FOR THE DEGREE OF
BACHELOR OF BUSINESS INFORMATION TECHNOLOGY
AND
FOURTH YEAR, SECOND SEMESTER EXAMINATION FOR THE DEGREE OF
BACHELOR OF BUSINESS INFORMATION TECHNOLOGY

CIT 3153: OBJECT- ORIENTED PROGRAMMING I

DATE: APRIL 2023 TIME: 2 HOURS

INSTRUCTIONS: Answer Question ONE and any other TWO questions.

QUESTION ONE (30 MARKS)

a) Differentiate between the following terms as used in C++ programming. (4 Marks)


i. While loop and do.. while loop
ii. call by value and call by reference
iii. function declaration /prototype and function definition
b) Illustrate two ways of initializing a variable in C++ (2 Marks)
c) Define class vehicle with member variables yom and regno. Delare an object from the class
and initialize its variables using a constructor. (4 Marks)
d) Write the syntax for declaring a derived class (2 Marks)
e) When and why would a C++ programmer use an inline function? (2 Marks)
f) Explain general structure of an object-oriented program using C++ (4 Marks)
g) When passing parameters by reference to a function, why would a programmer consider using
the constant arguments. (2 Marks)
h) Use an example to demonstrate how a two-dimensional array is declared in C++.
(2 Marks)
i) Study the following C++ program segment and answer the questions that follows
Class patient
{
int patientno;
int age;
char gender;
double weight;
public:
void getdata ();
void discharge ();
void admit ();
};
i. Explain two access specifiers used in the program segment. (4 Marks)
ii. Explain the significance of the keyword void as used in this program segment.
(2 Marks)

QUESTION TWO (20 MARKS)

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)

QUESTION FOUR (20 MARKS)

a) Write the syntax for declaring a class in C++ programming. (2 Marks)


b) Using a for loop, write a C++ program to display all multiples of any number entered by a user.
The program should stop once a multiple that is greater than 100 is reached. For instance, when
a user enters 8, all multiples of 8 are displayed as indicated below.
i.e 8,16,24,32,40, 48…, 96,104 (6 Marks)
c) State six characteristics of class constructors (6 Marks)
d) Write a C++ code that declares a class called employee, with a float private data salary and
public functions set_salary and get_salary. Then create an object called empl from the calss
(6 Marks

QUESTION FIVE (20 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;

i. Declare an integer variable var2 (1 Mark)


ii. Assign a value 20 to variable var 2 (1 Mark)
iii. Declare and initialize an integer variable var 3 to 30 (1 Mark)
iv. Declare a reference ref, to an integer variable var 2 (1 Mark)
v. Declare an integer pointer ptr. (1 Mark)
vi. Assign the pointer ptr to the address of the variable var 2 (1 Mark)

You might also like