Nepal Engineering College

Changunarayan, Bhaktapur
Level: Bachelor Year: 2015
Program: B.E. Full marks: 100
Course: Object Oriented Programming in C++ Time: 3 hours

NB : Candidates are required to give their answers in their own words as far as practicable.
The figures in the margin indicate full marks.
Attempt all questions.

1 a) Discuss the essential features of object oriented programming. 7
What are the differences between programming in small and programming in
large. Or
Encapsulation helps in data protection. How this protection occurs in case of
classes in C++?
b) How computation is taken as simulation? Discuss nonlinear behavior of 4+4
complexity in object oriented programming.
Explain the following term with suitable example: Agents, Responsibility,
Messages, and Methods
In what ways does Object Oriented Programming help in coping with
programming complexity?
2 a) What are different visibility labels used in C++? Explain their functionalities
with examples.
Differentiate class and structure. Explain them with example
Explain the following:
a. responsibility implies non-interference
b. computation as simulation
b) Write a program to take distance in feet and inches through constructor and add 8
two distances passing objects as arguments.
Create a new class named City that will have two member variables CityName
(char[20]), and DistFromKtm (float). Add member functions to set and retrieve
the CityName and DistFromKtm separately. Add new member function
AddDistance that takes two arguments of class City and returns the sum of
DistFromKtm of two arguments. In the main function, initialise three city
objects. Set the first and second city to be Pokhara and Dhangadi. Display the
sum of DistFromKtm of Pokhara and Dhangadi calling AddDistance function
of third City object.
What is de-constructor? Can you have two destructors in a program? Give
example to support your reason.
3 a) List out the features of constructor. Explain different types of constructor with 2+5
What are the advantages of using a friend function? List different types of
classes and explain any two.
Define friend function and inline function. What are the merits and demerits of
friend functions?
b) Define the terms subtype, subclass and principle of substitutability. What are 3+5
different forms of inheritance? Discuss.
What is a virtual function? When do we make a function virtual and when we
make a function pure virtual? Explain with a suitable example.
How does inheritance reuse the existing code ? Explain them with example.

4 Create a class stud_info to take information of student. Derive two classes exam 7
and library to take information related to respective ones for the student. In
main( ), execute all the functions in each classes.
What is memory recovery? How does stack differ from heap memory

What is virtual base class and when do we make a class virtual? Write an
example to illustrate the concept of virtual base class.

b) Is it mandatory to create constructor in derived class if the base class has one? 8
Illustrate giving suitable examples.
Write a program using only constructor to find the area of a square and
rectangle. Also initialize the object dynamically.
In what order are the class constructors called when a derived class object is

5 a) Define early and late binding in C++. When it becomes necessary to make the 3+5
function virtual? Explain giving an example.
What is hybrid inheritance? Does ambiguity occurs in this type of in this type
of inheritance? If yes explain it.
When do we make a virtual function “pure”? What are the implications of
making a function pure virtual function?
b) What are the operators that cannot be overloaded? Write a program to find 1+6
factorial of a given number n overloading ++ operator.
Develop a complete program for an institution which wishes to maintain a
database of its staff. Declare a base class STAFF which include staff_id and
name. Now develop records for the following staffs with the given information
i. Lecturer (subject, department)
ii. Administrative staff (post, department)
Each staff members should inherit staff_id and name from base class.
Write a program to generate the Fibonacci series overloading ++ operator.
6 a) Write a program to convert given polar number to rectangular representation. 7
(Use concept of type conversion)
What is exception handling? Discuss about the try throw and catch statements
We have two classes X and Y. If a is an object of X and b is an object of Y and
we want to say a=b; what type of conversion routine should be used. Give an
example to illustrate.

b) What is STL? Explain about function and class templates with suitable 2+6
Write a program using template to add two integers; two floats and one integer
and one float numbers respectively. Display the final result in float.
A template can be considered as a kind of macro. Explain the difference
between them.
4 Write short notes: (any two) 5X2
a. New and delete operators
b. CRC
c. this pointer
d. Interface and implementation
e. Exception handling