MABS Institution
11th Computer Science Monthly Test -1 ( Inheritance )-Aug 2020
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
If a base class and a derived class each include a member function with the same name and arguments, which member function will be called by the object of the derived class if the scope resolution operator is not used?
-
In what multilevel and multiple inheritance differ though both contains many base class?
-
Write the main advantages of Inheritance (or) Why was the concept of inheritance introduced in objected oriented language?
-
What is a base class?
-
In what situation shadowing base class function inderived class arises? How will you resolve the situation?
-
Write some facts about the execution of constructors and destructors in inheritance.
-
What do you mean by overriding?
-
Why do you need for inheritance?
-
-
What are the points to be noted while deriving a new class?
-
Explain the uses of private, protected and public inheritance.
-
-
Write the output of the following program.//Implementation of Single Inheritance using public
visibility mode
#include < iostream >
using namespace std;
class Shape
{
private:
int count;
protected:
int width;
int height;
public:
void setWidth(int w)
{
width=w;
}
void setHeight(int h)
{
height=h;
}
};
class Rectangle: publicShape
{
public:
int getArea()
{
return (width * height);
}
};
int main()
{
Rectangle Rect;
Rect.setWidth( 5);
Rect.setHeight(7);
II Print the area of theobject.
cour<< "Total area: "<< Rect.getArea() << endl;
return ();
} -
Can a derived class get access privilege for a private member of the base class? If yes, how?
-
What is the difference between polymorphism and inheritance though are used for reusability of code?
-
Write the output of the following program.
#include< iostream >
using namespace std;
class T
{
public:
int x;
void foot()
{
x = 6; // same as this->x = 6;
this ->x = 5; // explicit use of this ->
cout<x;
}
void foo(int x) // parameter x shadows the member
with the same name
{
this->x = x; // unqualified x refers to the
parameter.'this->' required for disambiguation
cout<< endl << x <<" "<x;
}};
int main()
{
T t1,t2;
t1.foot();
t2.food();
} -
Write the output of the following program based on the information given below.
The student Raguram studying in class XII and his roll number is 11201 and date of birth is 14/01/2002. and he scored 100 marks in all the subjects -
Suppose we have following C ++ program:
#include < iostream.h >
class A
{ public:
A() {cout<<"A";}
~A() {cout<<"~A";}
};
classB
{ public:
B () {cout<< "B";}
~B () { cout<< "~B"}
};
class C
{ public:
C() {cout << "C";}
~c () {cout <<~"C";}
private :
Ba;Ab;
};
classD
{ public:
D() {cout<<"D";}
~D() {cout<<"~D";}
};
Class E : Public C
{ public;
E() {cout<< "E";}
~E () {cout-c "~E";}
private:
Dd; Bb;
};
voidmain()
} Ee;
cout << endl;
Assuming that the program complies and runs correctly, what does it print out? -
Explain the different types of inheritance.
-
Write the output of the. following program.
#include< iostream >
using namespace std;
class base
{
public:
base( )
{
cout<<"\nConstructor of base class ...";
}
~base( )
{
cout << "\nDestructor of base class .... ";
}
} ;
class derived:public base
{
public:
derived()
{
cout << "\nConstructor of derived ...";
}
~derived( )
{
cout << "\nDestructor of derived ...";
}
};
class derived 1 :public derived
{
public:
derived1( )
{
cout << "n\nConstructor of derivedl ...";
}
~derived 10
{
cout << "\nDestructor of derivedl ...";
}
};
. int main ()
{
derived1 x;
return 0;
} -
Explain the different visibility mode through pictorial representation.
-
-
Answer the questions (i) to (iv) based on the
following code :
class Teacher
{ char TNo[5], TName [20], Dept[10];
int Workload;
protected:
float Salary ;
void AssignSal (float) ;
public:
Teacher ( );
void TEntry ( ) ;
void TDisplay ( ) ;
};
class student
{
char Admno[10], SName [20], Stream [10];
protected:
intAttendance, TotMarks;
public:
Student ( );
void SEntry ( ) ;
void SDisplay ( ) ;
};
class School: public Student, public Teacher
{
char SCode [10], SchName [20] ;
public:
School ();
void SchEntry ( ) ;
void Schfrisplay ( ) ; };
i) Which type of Inheritance is depicted by the above example?
(ii) Identify the member function(s) that cannot be called directly from the objects of class School from the following:
TEntry ()
SDisplay( )
SchEntry( )
(iii) Write name of all the member(s) accessible from member functions of class School.
(iv) If class School was derived privately from class Teacher and privately from class Student; then, name the member function(s) that could be accessed through objects of class school. -
Define the constructors for the following
definitions:
class A { intX;
floaty;
public:
A (int, float);
};
class B : public A
{ public:
};
-
-
(a) Define Multilevel and Multiple inheritance in context of object Oriented Programming Code suitable example to illustrate the same.
(b) Answer the questions (i) to (iii) based on the following code:
class stationery
{
char Type ;
char manufacturer [10] ;
public:
stationery ( );
void Read_Sta_details ();
void Disp_sta_details( ) ;
};
class office: public stationery
}
int no_of types;
float cost_of_sta ;
public:
void Read_off_details( );
void Disp_off details( ) ;
};
class printer: private office
{
int no_of users ;
char delivary_date[10];
public:
void Read_pri _details( );
void Disp_pri _details( ) ;
};
voidmain()
{ printer Myprinter ;
}
(i) Mention the member names which are accessible by MyPrinter declared in main( ) function.
(ii) What is the size of Myprinter in bytes?
(iii) Mention the names of functions accessible from the member function Read yri-details ( ) of class printer. -
Write the output of the following program
#include< iostream >
using namespace std;
class A
{
protected:
int x;
public:
void show()
{
cout<<"x = "<}
A()
{
cout<}
~A( )
{
cout<}
};
class B : public A
{
{
protected:
int y;
public:
B(int x, int y)
{
this->x = x; //this -> is used to denote the objects datamember
this->y = y; //this -> is used to denote the objects datamember
}
B( )
{
cout<}
~B( )
{
cout<}
void show( )
{
cout<<"x = "<cout<<"y = "< }
};
int main( )
{
A objA;
B objB(30, 20);
objB.show( );
return 0;
} -
Debug the following program
Output
-------------
15
14
13
Program :
-------------
%include< iostream.h >
#include< conio.h >
Class A
{
public;
int a1,a2:a3;
Void getdata[ ]
{
a1=15;
a2=13;a3=13;
}
}
Class B:: public A( )
{
PUBLIC
voidfunc( )
{
in
t b1:b2:b3;
A::g
etdata[ ];
b1=a1;
b2=a2;
a3=a3;
co
ut<}
void main( )
{
clrscr( )
B der;
der1:func( );
getch( );
}