Ics 2104 Object Oriented Programming I
Ics 2104 Object Oriented Programming I
QUESTION ONE
a) Choose FIVE features of the object-oriented paradigm. Describe what they are, why they
are important and give an example of EACH feature, either with code or with a diagram
(10 marks)
d) Explain why encapsulation is a key concept when working with objects. (3 marks)
e) When would private and protected class members be used in an object-oriented program?
Clearly distinguish between them. (3 marks)
1
QUESTION TWO
b) A function add takes 2 parameters of typer double and returns their sum.
c) The class diagram below represents a Van Hire system that records the hiring of van. In
an object-oriented programming language, write code to implement the class diagram
below. Within your code provide a default constructor and a destructor for each class.
(10 marks)
QUESTION THREE
a) Write a C++ program to explain the use of the IF..ELSE statement in any C ++ program.
(4 marks)
c) Explain what is type conversion and how it can be achieved in C++? (4 marks)
e) With the help of a good code example; explain the difference between local and global
variables. (4 marks)
QUESTION FOUR
b) Write code to open a file and write some data into the file (6 marks)
2
c) Define dynamic binding and give an example of how it is implemented in OOP (4 marks)
d) Design and implement a class “Employee” using C ++. The class should have the
following features:
It should store the employee ID, name, department and present total salary of an
employee.
The class should have a function that can input the values in an object.
The class should also have a function that can display the content of an object.
The class should have another function that takes ID as a parameter and displays the
department of the person whose employee ID is same as the ID given. Demonstrate all
the functions by creating an array of five “employee” objects in the main () function.
(8 marks)