Education In Pakistan

Papers, Notes, Books & Help For Students


Tag: VU. CS304 –. object. oriented .programming. (Session – 1 ). MIDTERM .EXAMINATION .SPRING .2005

VU CS304 – object oriented programming (Session – 1 ) MIDTERM EXAMINATION SPRING 2005



Question No: 1

( Marks: 2 )

– Please choose one

Which of the statements is true about destructor?

► Destructors are used to initialize data members

Destructors return types are always void

Destructors are called in reverse order of constructor called in a class hierarchy

Destructors are used to display the data members of their respective class

Question No: 2

( Marks: 2 )

– Please choose one

Identify the type of variable that is part of a class, yet is not part of an object of that class.





Question No: 3

( Marks: 2 )

– Please choose one

Which of the following operators can not be overloaded?

► ++

► new

► sizeof

► =


Question No: 4

( Marks: 2 )

– Please choose one

Target function for a call is selected at compile time in case of

Static binding



Dynamic binding

Question No: 5

( Marks: 2 )

– Please choose one

Suppose it is required to implement a single functionality with different data type, which of the

following techniques should be used

► Inheritance

► Friend function

► Templates

► Encapsulation

Question No: 6

( Marks: 5 )

Identify and correct the error(s) in the given code segment.

template< typename T >

class Parent {

// …


template< >

class Child< int > : public Parent {

// …


int main() {

Parent< char > obj;

Child< int > obj2;

return 0;



Question No: 7

( Marks: 10 )

Given are two classes A and B. class B is inherited from class A. Write a code snippet(for main

function) that polymorphically call the method of class B. Also what changes do you suggest in the

given code segment that are required to call the class B method polymorphically.

class A



void method() { cout<<“A’s method \n”; }


class B : public A



void method() { cout<<“B’s method\n”; }


Question No: 8

( Marks: 10 )

Implement the given class hierarchy where there exist a relation ship of inheritance between

Employee and Contract (for contract employee). The Display() function of Contract should

display the data that includes ; Name, Num_hours, Per_hour_sal, Salary

Monthly salary of contract employee is calculated as

Salary = Per_hour_sal*Num_hours


Question No: 9

( Marks: 15 )

A Real world Problem:

This is a business rule of a bank that the Balance of customer must always be Positive,

Further that it is also a business rule that a customer can not withdraw amount greater than his/her

current balance.

Question statement

You are required to write a C++ program to solve this real world problem, using Exception


Your program should consist of a class Customer and 4 instance variables. Cust_name,

Cust_AC_No, Cust_balance, Amount_withdraw.


: Customer Name

Cust_AC_No : Customer Account Number

Cust_balance : Customer Balance

Amount_withdraw : Amount that is to be withdraw

The class should further consists of getter and setter function for each instance variable.

The setter function of Cust_balance consists of a try and a catch block, if the user enters the

balance less than zero (means negative, which is not possible) then this function should throw an

exception, and its corresponding catch block should handle this exception by providing another

opportunity to the user to enter the balance again.

Similarly the setter of Amount_withdraw variable should also have a try and a catch blocks. If the

user enters the withdraw amount greater than the current balance then this function should throw

an exception, and its corresponding catch block should handle this exception.


In main function just declare an object of Customer class and call all its setter and getter functions.

Education In Pakistan © 2016