Assignment: Inheritance Class: Xii, C++ (Computer Science)
Assignment: Inheritance Class: Xii, C++ (Computer Science)
Assignment: Inheritance Class: Xii, C++ (Computer Science)
Q- 1 Give the following class definition answers the question that is follow:
class Living{ char name [20];
protected :
int jaws;
public :int eyes;
void inputdata(char , int);
void outputdata(); }
class animal : private living_being
{ int tail;
protected : int legs;
public : int nails;
void readdata(int,int);
void writedata ( ); };
class cow : public animal
{ int horn_size;
public : void fetchdata(int);
void displaydata( );};
(a) Name the members, which can be accessed from the member functions of class animal.
(b) Name the data member(s) that can be accessed from function displaydata( ).
(c) Name the data member(s) that can be accessed by an object of cow class.
(d) Name the type of inheritance shown above?
(e) What will be the size of an object (in bytes) of class animal?
Q-2 Give the following class definition answer the question that is follow:
class company { char Location[20];
double budget,income;
protected : void account( );
public : company( );
void register( );
void show( ); };
class Factory : public company
{ char Location[20];
int workers;
protected : double salary;
void computer( );
public : factory( );
void Enter( );
void show( ); };
class shop: private company
{ char Location[20];
float Area;
double sale;
public : shop( );
void input();
void output(); };
(a) Name the data members, which can be accessed from the member functions of class shop.
(b) Name the member(s) that can be accessed from the object of class shop.
(c) Name the member(s) that can be accessed by an object of class factory.
(d) What will be the size of an object (in bytes) of class Factory?
(e) Name the type of inheritance.Which class constructor will be called first at the time of making object of
class shop?
Q-3 Give the following class definition answer the question that is follow:
class DRUG { char catg[10];
char DOF[10], comp[20];
public: float price;
DRUG( );
void endrug( );
void showdrug( ); };
class TABLET : protected DRUG
{ protected: char tname[30],volabel[20];
public: TABLET( );
void entab( );
void showtab( ); };
class PAINKILLER : public TABLET
{ int dose, usedays;
char seffect[20];
public : void entpain( );
void showpain( ); };
i) How many bytes will be required by an object of TABLET?
ii) Write names of the entire member called by a function of class TABLET.
iii) Write names off all members accessible from object of class PAINKILLER.
iv) Name the type of inheritance and order of constructor invocation when object of class
PAINKILLER is created
Q-4 Read the following class declaration and answer the questions from (i) to (iv) :
class Teacher { char TNo[7],TName[25],Dept[12];
int Wload;
protected: double Sal;
void AssignSal(double);
public: Teacher( );
Teacher(Double S);
void TeaNew( );
void TeaDisplay( );};
class Student : public Teacher
{ char ANo[6],SName[15],Group[7];
protected: int Att,Total;
public: Student( );
void StuAccept( );
void StuDisplay( ); };
class School: protected Student
{ char SchCode[9],SchName[15];
public: School( );
void SchAccept( );
void SchDisplay( );};
(a) Name the type of inheritance.How many bytes will be reserved for an object of type school?
(b) Name the members that can be called by object of type Student.
(c) Name the data members that can be accessed by objects of type School.
(d) Identify the member function(s) that cannot be called directly from the objects of class School from the
following: a) TeaNew( ) (b) StuAccept( ) (c) SchDisplay( ) (d)AssignSal( )
(e) Name the members which can be called by the function of class School
Q-5 Answer the following (i) to (iv) based on the following code:
class PUBLISHER
{ char Pub[12];
double Turnover;
protected: void Register ();
public: Publisher ();
void Enter( );
void Display( ); };
class BRANCH
{ char CITY[20];
protected: float Employees;
public: BRANCH();
void Haveit();
void Giveit(); };
class Author: private BRANCH , public PUBLISHER
{ int Acode;
char Aname[20];
float amount;
public: AUTHOR( );
void Start( );
void Show(); };
(a) Write the names of the data members, which are accessible from objects belonging to class AUTHOR .
(b) Write the names of all the member functions which are accessible from objects belonging to the class
BRANCH.
(c) Write the names of all members which are accessible from member functions of class AUTHOR.
(d) How many bytes will be required by an object belonging to class AUTHOR? What will be the order of
constructor invocation
Q-6 Answer the following (i) to (iv) based on the following code:
class Chairperson { long CID ;
char CName[20] ;
protected : char Description[40] ;
void Allocate( ) ;
public : Chairperson( ) ;
void Assign( ) ;
void Show( ) ; } ;
class Director { int DID ;
char Dname[20] ;
protected :
char Profile[30] ;
public : Director( ) ; void Input( ) ; void output( ) ;};
class Company : public Chairperson,protected Director
{ int CID ;
char City[20] , Country[20] ;
public : Company( ) ;
void Enter( ) ;
void show ( ) ; } ;
void main()
{ company C; }
(a) Which type of Inheritance out of the following is specifically is illustrated in the above C++ code ?
(a) Single Level Inheritance (b) Multi Level Inheritance (c) Multiple Inheritance
(b) Write the names of members, which are accessible by objects of class type Company.
(c) Write the name of all the member functions, which are accessible by objects of class type company.
(d) Write the names of all members, which are accessible from member functions of class Director.
(e) Write a statement to call function show of class Chairperson by using object of class Company.
Q-7 Answer the following questions i) to iv) based on the following
class AC
{ char Model[10];
charpur_date[10];
char Company[20];
public( ); AC( );
void entercardetail( );
void showcardetail( ); };
class Accessories : protected AC
{ protected: char Stabilizer[30];
char AC_cover[20];
public: float Price;
Accessories( );
void Enterdetail( );
void showdetail( ); };
class Dealer : public Accessories
{ int N-dealers;
char dname[20];
int Nproducts;
public: Dealer( );
void EnterDealers( );
void ShowDealers( ); };
i) How many bytes will be required by an object of class Dealer and class Accessories?
ii) Which type of inheritance is illustrated in the above C++ code? Write the order of constructor invocation
when object of class dealer is created.
iii) Write names of all the members which are accessible from the objects of class Dealer.
iv) Write names of all the member variable which are accessible from the functions of class Dealer.
Q-8 Answer the following questions i) to iv) based on the following
class PPP { int H;
protected : int S;
public : int X;
void INPUT (int);
void OUT( ); };
class QQQ { int T;
protected : int U;
void cal( );
public : void INDATA( int ,int);
void OUTDATA( ); };
class RRR: public QQQ , private PPP
{ int M;
public: void DISP(void); };
i) Name the data member (s) that can be accessed from function DISP ( ).
ii) Name all the members (s), which can be accessed from the objects of class RRR.
iii) What will be the size of object of class RRR?
iv) What will be the order of constructor invocation when object of class RRR is made?
Q-9 Answer the following questions i) to iv) based on the following
class QUALITY { private :
char Material [30];
float thickness;
protected : char manufacturer[20];
public: QUALITY( );
void READ( );
void SHOW( ); };
class QTY: private QUALITY
{ long order;
protected: int stock;
public: double *p;
float cost;
QTY( );
void RQTY ( );
void SHOW( ); };
class FABRIC: protected QTY
{ private: int fcode,fcost;
public:
FABRIC( );
void RFABRIC( );
void SFABRIC( ); };
(a) Mention the member names that are accessible by an object of QTY class.
(b) Name the data members which can be accessed by the objects of FABRIC class.
(c) Name the members that can be accessed by the function of FABRIC class.
(d) Name the member which can be called by the function of class QTY
(e) Name the type of constructor. Write a statement to call function SHOW( ) of class QUALITY by the object
Q of class QTY.
(f) What is the order of constructor invocation? How many bytes will be occupied by an object of class
FABRIC?
Q-10 Answer the questions (i) to (iv) based on the following:
class indoor_sports
{ int id;
char Iname[20];
char coach[20];
protected:
int rank,fee;
void get_ifee();
public: char Sname[20];
void iEntry();
void ishow(); };
class outdoor_sports : private indoor_sports
{ int Oid;
char Oname[20];
char Ocoach[20];
protected:
int Orank,Ofee;
void get_ofee();
public: void OEntry();
void OShow(); };
class sports: public indoor_sports
{ char rules[20];
public: sports();
void registration();
void showdata(); };
i) Name the type of inheritance illustrated in the above C++ code. What will be the size of the object
belonging to class indoor_sports?
ii) Write the names of all which are accessible from the member function of class outdoor_sports.
iii) Write the names of all the members, which are accessible from the objects belonging to class
outdoor_sports.
iv) Write the names of the entire member which are accessible from the member function of class sports.
Q-11 How does inheritance influences the working of Constructors and Destructors?
Q-12 Write short note on Virtual Base class? Explain with example
Q-12 What is containership? How does it differ from inheritance?
Q-13 Define Constructor for the classes defined below:
class ABC { int a;
public : float B;
______// the constructor definition
};
class XYZ { int x;
public : float y;