Final Oop Paper Spring 2020
Final Oop Paper Spring 2020
Q1
a) What is polymorphism? Explain two types of polymorphism with code examples. [marks
4]
b) When a derived class of an abstract base class remains abstract? How can we make derived
class of abstract class as concrete class?
[marks 2]
c) List out the operators that cannot be overloaded using Friend function.? Why? [marks
2]
d) What is difference between function overloading and function overriding?
[marks 2]
Q2
a) Predict output of the following program. If there is an error Write the additional code to make
these programs run. [marks 4]
#include <iostream.h>
#include <string.h>
class student
{
private:
char *name;
int roll;
int semester;
public:
student(): roll(0), semester(0)
{
name=new char[20];
strcpy(name, "");
}
student(char *n, int r, int s): roll(r), semester(s)
{
name=new char[strlen(n) + 1];
strcpy(name, n);
}
void set()
{
cout<<"Enter name: "<<endl;
cin>>name;
cout<<"Enter roll no: "<<endl;
cin>>roll;
cout<<"Enter semester: "<<endl;
cin>>semester;
}
void show()
{
cout<<"Name: "<<name<<endl;
cout<<"Roll NO: "<<roll<<endl;
cout<<"Semester: "<<semester<<endl;
}
~student() {
delete[] name; }
};
void main()
{
student s1("Bjarne Stroustrup", 3, 3);
s1.show();
student s2(s1);
s2.show();
s2.set();
cout<<"After setting s2:"<<endl;
cout<<"Data of student S1"<<endl;
s1.show();
cout<<"Data of student s2"<<endl;
s2.show();
return 0;
}
b) Consider the following list of classes; Car, Steering Wheel, Vehicle, Van, Minivan, Audio
System, Parking Lot. Your task is to describe all of the is-a and has-a relationships between
these classes. Include an inheritance hierarchy for all classes that fit. Fill each cell of the
table below with is-a or has-a relationship while leaving cells empty where no relation is
applicable. [marks 6]
Car
Van
Mini Van
Steering
Wheel
Audio System
Parking Lot
i) Find the output of following C++ program if ii) Predict output if no there is no error
there is error correct it. #include<iostream>
int main()
{
Derived d;
return 0;
}
Q5 [5+3+4]
i. Name the type of inheritance of following figures in which, “P” is for parent and “C”
for Child.
P P P P1
P1 P2 P3
C C1 C1 C2 C3 C1 P2
C1
C3
C2
ii. In Fig. 1, what will be the status of member(s) of parent class (P) in child class (C);
a) If members of P are private, protected, public and inheritance
visibility/access specifier is private?
___________________________________________________________________
___________________________________________________________________
__________________________
b) If members of P are private, protected, public and inheritance
visibility/access specifier is protected?
_________________________________________________________________
_________________________________________________________________
_____________________________
c) If members of P are private, protected and inheritance visibility/access
specifier is public?
________________________________________________________________
________________________________________________________________
________________________________________________________________
iii. Write and exemplary code for Fig. 2 in which, P is an abstract class. You need to
inherit member(s) of abstract class in C2.
[Hint: you can use just getId or setID function for example]
Ans:________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________
__________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________
Ans:
___________________________________________________________________________
________________________________________________________