BIT 2108 OBJECT ORIENTED PROGRAMMING I KCA Past Paper

UNIVERSITY EXAMINATIONS: 2011/2012
SECOND YEAR EXAMINATION FOR THE BACHELOR OF
SCIENCE IN INFORMATION TECHNOLOGY
BIT 2108 OBJECT ORIENTED PROGRAMMING I
DATE: AUGUST, 2012 TIME: 2 HOURS
INSTRUCTIONS: Answer Question ONE and any other TWO

QUESTION ONE
a) Application development has increasingly become complex to develop than it was
years ago. Give FOUR reasons why you think this is so (4 Marks)
b) Give three characteristics of an object (3 Marks)
c) Give four benefits of object technology (4 Marks)
d) Explain the following component of Object Technology
i. Object Oriented Analysis
ii. Object Oriented Design
iii. Object Oriented Programming
(6 Marks)
e) With examples spell out two differences between Object Based Programming and
Object Oriented Programming Languages (4 Marks)
f) Give three application area of oriented application (3 Marks)
g) Explain with examples how pointers can be used for memory allocation (3 Marks)
h) Explain the structure of a C++ program and show how the concept of Client Server
concept is achieved (3 Marks)
QUESTION TWO
a) Predict the output of the following program
#include <iostream>
using namespace std;
class vector
{
public:
double x;
double y;
double surface ()
{
double s;
s = x * y;
if (s < 0) s = -s;
return s;
}
};
int main ()
{
vector a;
a.x = 3;
a.y = 4;
cout << “The surface of a: ” << a.surface() << endl;
return 0;
}
(4 Marks)
b) Describe the following terms as used in OOP
i. Static memory allocation
ii. Dynamic memory allocation
iii. Constructors
iv. Destructors
(8 Marks)
c) Write a program that displays an invoice of several items. It should contain the
item name, quantity, price, and total cost on each line for the quantity and item
cost. It also contains methods to get and set item name, quantity, and price.
Objects are created in main and invoices printed. (8 Marks)
QUESTION THREE
a) Write a program that calculates and displays the weekly salary for an employee
who earns $25 an hour, works 40 regular hours, 13 overtime hours, and earns
time and one-half (wage * 1.5) for overtime hours worked. Create a separate
method to do the calculation and return the result to be displayed. Your program
contain a class that holds the employee details indicated as well as the method
to do the computation (8 Marks)
b) Define the following
i. Method
ii. Inheritance
iii. Class
(6 Marks)
c) Create a class named Box that includes integer data fields for length, width, and
height. Create three constructors that require one, two, and three arguments,
respectively. When one argument is used, assign it to length, assign zeros to
height and width, and print “Line created”. When two arguments are used,
assign them to length and width, assign zero to height, and print “Rectangle
created”. When three arguments are used, assign them to the three variables and
print “Box created”. (6 Marks)
QUESTION FOUR
a) With a valid example, explain how an ADT are created. (3 Marks)
b) Describe how abstraction is achieved when using class object to implement
systems. (3 Marks)
c) Describe code reuse as used in application development. (2 Marks)
d) Differentiate between multiple and hierarchical inheritance. (2 Marks)
e) Explain how classes achieve code hiding and code reuse in a program. Write a
program to help explain your answer. (10 Marks)
QUESTION FIVE
a) Define what a friend function is and predict the output of the following program
#include <iostream>
using namespace std;
class CRectangle {
int width, height;
public:
void set_values (int, int);
int area () {return (width * height);}
friend CRectangle duplicate (CRectangle);
};
void CRectangle::set_values (int a, int b) {
width = a;
height = b;
}
CRectangle duplicate (CRectangle rectparam)
{
CRectangle rectres;
rectres.width = rectparam.width*2;
rectres.height = rectparam.height*2;
5
return (rectres);
}
int main () {
CRectangle rect, rectb;
rect.set_values (2,3);
rectb = duplicate (rect);
cout << rectb.area();
return 0;
}
(6 Marks)
b) Give the following class CPolygon, give a definition of the class CRectangle that
inherits CPolygon with a method that compute the area and perimeter of a
Rectangle Design also the class CTriangle that inherits from CPolygon with
additional method that compute the area of a triangle.

Create the main program that demonstrate how the two derived classes are
invoked
#include <iostream>
using namespace std;
class CPolygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b;}
};
(9 Marks)
c) When implementing inheritance, some elements from the base class are not
passed to the derived class. List those methods that are not inherited (3 Marks)
d) Explain what you understand by the following:
i. Virtual function
ii. Multiple inheritance
(2 Marks)

(Visited 118 times, 1 visits today)
Share this:

Written by