Object Oriented Programming BSCS 2nd Term 2017 Past Paper UOS

University of Sargodha
BS 2nd Term Examination 2017
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 in 2-3 lines each on your answer sheet. (2*12)
i. Why constructors are used? Give an example of parameterized constructor?
ii. Which access specifier is taken as default if no access specifier is explicitly mentioned? Give an example in favour of your answer.
iii. How a virtual function is created? When is it used?
iv. Write the statement (only header) in which class B inherits class A privately.
v. Why exception handling is used?
vi. How abstract class is created in C++?
vii. What do you mean by function overriding?
viii. What is operator overloading?
ix. Which operator is used in order to access a member function of a class when dynamic object is created? Also give an example to access a function by using dynamic object.
x. Write names of two operators that cannot be overloaded?
xi. How static member function is differentiated from non-static function in calling a function?
xii. What is default constructor? Can an object be created by using default constructor when only parameterized constructor is defined in a class?
Subjective Part (3*12)
Q.2. Create a Distance class having data members as feet (of type int) and inches (of type float). Write at least two constructors of the class and a suitable method to compare two objects of the class to determine whether two objects are equal or not? The result is displayed by main().
(Note: the number of inches in each distance is less than 12).
Q.3. Write a class named Array that contains an array of integers as data member. The class contains the following member functions:
- A constructor that initializes the array element to 0.
- Input function to input the values in the array.
- Display function to display the values of array.
- A member function to make the odd values of the array three times (multiply by 3).
Q.4. Write a program that declares a Data class. It consists of only one data member count (of type int). Write appropriate constructor and other member function in order to validate the following statement in main().
obj++;
++obj;
where obj is an object of Data class.
Q.5. Create a Person class having name (i.e. array of char) as a data member. Create another class Teacher that inherits from Person class and declares salary (of type double). Write suitable constructors (multiple) of Teacher class to initialize data members. Create two objects of Teacher class in main() with two different constructors and display them.
Q.6. Create a class Geometry without any data member. Another class Circle is inherited from Geometry class which declares radius (of type float) as its data member. Derive another class Square from Geometry that declares side as its data member (of type int). By using the concept of polymorphism, display the area and perimeter of Circle and Square in main().
Area of Circle: πr²
Perimeter of Circle: 2πr
Area of Square: r²
Perimeter of Square: 4r