MENU

Chapter 5 Inheritance Solutions

Question - 11 : -
Answer the questions (i) to (iv) based on the following:

class COMPANY
char Location[20]; 
double budget, income; 
protected: 
void Accounts(); 
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();
};
(i) Name the type of inheritance illustrated in the above C+ + code.
(ii) Write the name of data members which are accessible from the member 
functions of class SHOE
(iii) Write the name of member functions which are accessible 
from the objects of class FACTORY.
(iv) Write the name of data members which are accessible from the objects of class SHOE

Answer - 11 : -

(i) Hierarchical Inheritance
 
(ii) None
(iii) Enter(), Show(), Register( ), Accounts company :: Show ().
(iv) Data Members : NONE

Question - 12 : -
Answer the questions (i) to (iv) based on the following:

class ORGANIZATION
{
char Address[20];
double budget, income; 
protected: 
void Compute(); 
public:
ORGANIZATION();
void Get(); 
void Show();
};
class WORKAREA : public ORGANIZATION
{
charAddress[20]; 
int staff; 
protected: 
double pay; 
void Calculate(); 
public:
WORKAREA(); 
void Enter(); 
void Display();
};
class SHOWROOM:private
ORGANIZATION
{
char Address[20]; 
float Area; 
double Sale; 
public:
SHOWROOM(); 
void Enter(); 
void Show();
};
(i) Name the type of inheritance illustrated in the above C+ + code.
(ii) Write the name of data members 
which are accessible from the member functions of class SHOWROOM.
(iii) Write the name of member functions which are accessible 
from the objects of class WORKAREA.
(iv) Write the name of members which are accessible from the objects of class SHOWROOM.   

Answer - 12 : -

(i) Hierarchical Inheritance
 
(ii)  Address, Area, Sale, Budget, Income.
(iii) Enter(), Display(), Get (), Show()
(iv) Data Members: NONE
Member Functions: Enter(), Show()

Question - 13 : -
Answer the questions (i) to (iv) based on the following:

class indoor_sports
{
int i_id; 
char i_name[20]; 
char i_coach[20]; 
protected:
int i_rank,i_fee;
void get_ifee()
public: indoor_sports();
void iEntry();
void ishow();
};
class outdoor_sports
 {
int o_id; 
char o_name[20]; 
char o_coach[20]; 
protected;
int orank,ofee;
void get_ofee(); 
public;
outdoor_sports(); 
void oshow();
};
class sports:public indoor_sports, protected outdoor_sports
{
char rules [20]; 
public;
sports();
void registration(); 
void showdata();
};
(i)Name the type of inheritance illustrated in the above C+ + code.
(ii) Write the names of all the members, which are accessible 
from the objects belonging to class
outdoor_sports.
(iii) Write the name of member functions which are accessible 
from the objects of class sports.
(iv) What will be the size of the object belonging to class indoor_sports?

Answer - 13 : -

(i) Multiple Inheritance.
(ii) Data Member; None
Member Funcitons; oEntry(), oShow()
Note :
No marks to be awarded for any partial or additional answer (s)
(iii) registration(), showdat(), oEnty(), oShow(), get_ofee(), iEntryO, iShow(), get_ ifee()
Note :
No marks to be awarded for any partial or additional answer (s)
(iv) 46 Bytes

Question - 14 : -
Write the definition of a class DISTRICT in C++ with following description :
Private Member
–  Dcode
//Data member for code (an integer)
–  DName
//Data member for Name (a string)
–  DPop
//Data member for Population (a long int)
–  Area
//Data member for Area Coverage
(a float)
– Density
//Data member for Population Density
(a float)
– DenCal()
//A member function to calculate //Density as Pop/Area
Public Members
– Input()
//A function to allow user to enter
values of
//Dcode, DName, DPop, Area and call
DenCal () //function
– ShowALL()
//A function to display all the data
members
//also display a message “Highly Populated Area”
//if the Density is more than 12000

Answer - 14 : -

Class DISTRICT 
{
int DCode; 
char DName[20]; 
long int DPop;
Float Area;
Float Dens;
Void Dencal();
Public:
void Input(); 
void showALL();
};
void DISTICT::Input()
{
cin>>Dcode;
gets(DName);//OR cin>>Dname;
cin>>DPop;
cin>>Area;
Dencal();
}
void DISTRICT::ShowALL()
{
cout<
if(Dens>12000)cout<<"Highly Populated Area";
\\Ignore endl
}
void DISTRICT::Dencal()
{
Dens=DPop/Area;
}

Question - 15 : -
Answer the questions (i) to (iv) based on the following :

class PACKAGE
{
int PCode; 
char PDes[20];
protected:
float PQty; 
public :
PACKAGE();
void In();
void DispO;
};
class TRANSPORT
{
int TCode; 
protected:
char TName[20]; 
public:
TRANSPORT(); 
void Enter(); 
void Display();
};
class DELIVERY:public PACKAGE, private TRANSPORT 
{
char Address[40],Date[12]; 
public:
DELIVERY();
void Input(); 
void Show();
}
(i) Which type of Inheritance out of the following illustrated in the above example?
• Single Level Inheritance
• Multi Level Inheritance
• Multiple Inheritance
(ii) Write the names of all the data members, 
which are directly accessible from the member functions 
of class DELIVERY.
(iii) Write the names of all the member functions, 
which are directly accessible by an object of 
class DELIVERY.
(iv) What will be the order of execution of the constructors, 
when and object of class DELIVERY 
is declared ?

Answer - 15 : -

(i) Multiple Inheritance.
(ii) PQty, IName, Address, Date
(iii) Input(), show(), In(), Disp()
(iv) PACKAGE(), TRANSPORTO, DELIVERY()

Free - Previous Years Question Papers
×