Final-Term Exam: University of Management and Technology Object Oriented Programming
Final-Term Exam: University of Management and Technology Object Oriented Programming
Final-Term Exam: University of Management and Technology Object Oriented Programming
1|Page
UMT ID # S2019207003
Q1:
a. What are the 2 major situations where member initializer list is required? What is the the
difference between member and base initialization lists and when they are used?
b. Differentiate between shallow and deep copy. Provide a coding example also draw
diagram to show these concepts.
d. Discuss the magic of “virtual” in OOP. Why we need to make destructor virtual in
polymorphism.
2|Page
UMT ID # S2019207003
3|Page
UMT ID # S2019207003
2. CruiseShip class
Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have
the following members:
3. CargoShip class
Design a CargoShip class that is derived from the Ship class. The CargoShip class should have
the following members:
4. BattleShip class
Design a BattleShip class that is derived from the Ship class. The BattleShip class should have
the following members:
4|Page
UMT ID # S2019207003
5|Page
UMT ID # S2019207003
Q4:
How many times copy constructor called, in the given code when main function
will be executed? Explain the reason of each call of Copy constructor to get full
credit.
class Widget{
public:
Widget() {}
};
Widget f (Widget u){
Widget v(u);
Widget w=v;
return w;
}
int main() {
// your code goes here
Widget x;
Widget y = f(f(x));
return 0;
}
6|Page
UMT ID # S2019207003
Q5.
Consider the following real world electrical appliances and thinking in terms of
OOP (e.g. What are the relationships between them? Can you exploit the
inheritance between any of them? What are the polymorphic methods? Are there
any abstract classes? If so what are the pure virtual methods? etc.).
Electrical Appliances
oAudio
Hi-fi
Radio
Walkman
oRefrigeration
Fridge
Freezer
oTelephone
Fixed
Cordless
Cellular
All electrical appliances have a turnOn and turnOff method.
All audio appliances have an adjustVolume method.
All refrigeration appliances have an adjustTemperature method.
All telephones that have a dial and hangup method.
7|Page