Object Oriented Programming BSCS 2nd Term 2016 Past Paper UOS

University of Sargodha
BS 2nd Term Examination 2016
Subject: Computer Science
Paper: Object Oriented Programming (CMP:2124)
Time Allowed: 2:30 Hours
Maximum Marks: 60
Objective Part (Compulsory)
Q.1 Write short answers of the following questions in 2-3 lines only. (12*2)
i. What is destructor? How many parameters are passed to a destructor?
ii. What is difference b/w public and protected access specifier?
iii. What is diamond problem? Where this problem is encountered in inheritance?
iv. What are two categories of Inheritance?
v. What do you mean operator overloading? Can we introduce a new operator by using operator overloading?
vi. What is difference b/w try block & catch block?
vii. Write the syntax of header of a function of a class where + operator is overloaded to add two objects and one object is returned?
viii. What is difference between function overloading and function overriding?
ix. What do you know about Encapsulation?
x. Is new operator necessary to create object? When new operator is used?
xi. What are the necessary conditions for polymorphism?
xii. How static data member is different from non-static data member?
Subjective Part (12*3)
Q.2 Write a class Runner that contains the following data members:
- The name of runner
- The distance covered by runner
The class has the following member functions:
- Get function to input runner name and distance
- Show function to display runner name and distance
- Create two objects of the class and also display the name of the Runner who has covered longer distance.
Q.3 Write classes Array that contain the array of integers as data member. The class contain the member functions:
- A constructor that initializes the array element to -1.
- Input function to input the values in the array.
- Show function to display the values of array.
- A member function to make the values of the array two times.
Q.4 Write a program that declares a Shape class as abstract class. There are two classes Square (all sides are equal) and Right Triangle being derived from Shape class. Write suitable program to calculate the area and perimeter of the relevant shapes (i.e. Right Triangle and Square). Formulas used to calculate the area and perimeter are as follows:
Area of Square = (side)^2
Perimeter of Square = 4 * side
Area of Right Triangle = ½ * base * height
Perimeter of Right Triangle = side1 + side2 + side3
Note: use the principle of polymorphism in Q #4.
Q.5 Create a Distance class which has two data members feet and inches of type int and float respectively. Write the appropriate constructor and other member functions in order to add the corresponding values of two objects and storing the result in d3 by using expression d3.add(d1, d2) in the main function where d1, d2, d3 are the objects of Distance class.
Q.6 Create a Car class that includes name as its data member. Create another class Toyota that is derived from Car class and includes his Model # (int type) and colour (string type) as his data member. Write appropriate constructors (multiple constructors) and display method to create and display objects of Toyota class.