MABS Institution
11th Computer Science Weekly 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?
-
What do you mean by overriding?
-
What is difference between the members present in the private visibility mode and the members present in the public visibility mode
-
-
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 ();
}
-
-
What is the difference between polymorphism and inheritance though are used for reusability of code?
-
(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. -
Given the following set of definitions:
class x { :
};
class y : public x
{;
};
class z : public y
{;
};
(i) What order will the constructors and destructor's be invoked in? -
-
Explain the different types of inheritance.
-
Write the output of the following program.
# include < iostream >
class person
{
Public:
string profession;
int age;
Person() Profession ("unemployed"),
age (16) {}
void display ( )
{
cout-<<"My profession is:
"<cout-<< "My age is: "<< age< walk ();
talk ();
}
void walk()
{ cout-<< "I can walk" <}
void talk ()
{cout-<< "I can talk" <}
};
Class Teacher: Public Person
{
Public:
void teachrnaths ( )
{cout-<< "I can teach Maths" <}
};
Class Player: Public Person
{
Public:
void play football ( )
{ cout-<< "I can play football" <}
int main ()
{
Teacher t1;
t1.profession = "Teacher"
t1. age = 24 ;
t1. display ( ) ;
t1. teachmaths( );
Player f1;
f1. profession -= "footballer"
f1. age = 21
f1. display ( ) ;
f1. play football ( ) ;
return 0;
}
-
-
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;
}