0% found this document useful (0 votes)
144 views

Final Oop Paper Spring 2020

The document is an examination paper for an Object Oriented Programming subject. It contains 7 questions assessing various OOP concepts like polymorphism, inheritance, abstract classes, function overloading and overriding. The questions are both theoretical, asking to explain concepts, as well as practical, asking to write code snippets or predict program outputs.

Uploaded by

Rizwan Khadim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Final Oop Paper Spring 2020

The document is an examination paper for an Object Oriented Programming subject. It contains 7 questions assessing various OOP concepts like polymorphism, inheritance, abstract classes, function overloading and overriding. The questions are both theoretical, asking to explain concepts, as well as practical, asking to write code snippets or predict program outputs.

Uploaded by

Rizwan Khadim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Examination: IT department (Year 2020)

Subject: Object Oriented Programming (OOP)


Time Allowed: 4 hours Instructor: Mamoona Majid
Total marks: 43 weight age : 25 %
Student name: ________________________ student id: ________________________

Note: Attempt All the Questions.


Instructions:
If any question/ paper found similar will be considered as cheating and marked
as zero. This is an open book paper, but write answer of each question in your
own words. Copy paste from any source will be resulted as zero. Give to the
point answer and be specific as needed.

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]

Vehicle Car Van Mini Steering Audio Parking


Van Wheel System Lot
Vehicle

Car

Van

Mini Van

Steering
Wheel
Audio System
Parking Lot

C) Encircle true or false according to each of the following. [ 5 marks]

1. Base-class constructors are not inherited b derived classes. (T F)


2. A class is made abstract by declaring that class virtual. (T F)
3. Function overloading occurs during inheritance only. (T F)
4. Template function serve for function overloading only. (T F)
5. C++ does not allow multiple inheritance. (T F)

Q4 Predict output of the following: ( 3+3 )

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>

#include<iostream> using namespace std;


using namespace std; class Base1 {
class A public:
{ Base1()
public : { cout << " Base1's constructor called" <<
int x=20; endl; }
}; };
class B class Base2 {
{public : public:
int x=10; Base2()
}; { cout << "Base2's constructor called" <<
int main() endl; }
{ A obj1; class Derived: public Base1, public Base2 {
B obj2; public:
obj1 = obj2;
cout<< obj1.x; Derived()
cout<<endl; { cout << "Derived's constructor called" <<
return 0;} endl; }
}; };

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.

Fig. 1 Fig. 2 Fig. 3 Fig. 4 Fig. 5

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:________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________

Q6 At least 5 differences between Abstract and Concrete Classes ? [marks 5]

__________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________

Q7. How to make a class abstract? [marks 2]

Ans:
___________________________________________________________________________
________________________________________________________



You might also like