ASSIGNMENT OF INHERITANCE
Q1. Consider the following c++ code and
answer the questions from (i) to (iv):
class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal(); void
pentry();
void Pdisplay();
};
class Marks: private Personal
{
float M[5];
protected:
char Grade[5];
public:
Marks();
void Mentry();
void Mdisplay();
};
class Result: public Marks
{
float Total, Agg;
public:
char FinalGrade, comments[20];
Result();
void Rcalculate();
void Rdisplay();
};
(i) Which type of inheritance is
shown in the above example?
(ii) Write the names of those data
members, which can be directly accessed from the objects of class Result.
(iii) Write the names of those
member functions which can be directly accessed from the objects of class Result.
(iv) Write names of those data
members, which can be directly accessed from the Mentry() function of class Marks.
Q2. 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 names of data
members, which are accessible from member functions of class SHOP.
(iii) Write the names of all the
member functions, which are accessible from objects belonging to class FACTORY.
(iv) Write the names of all the
members, which are accessible from objects of class SHOP.
Q3. Answer the questions (i) to (iv)
based on the following:
class FaceToFace
{
char CenterCode [10] ;
public:
void Input ( ) ;
void Output ( ) ;
} ;
class Online
{
char website [50] ;
public:
void SiteIn ( ) ;
void SiteOut ( ) ;
} ;
class Training: public FaceToFace,
private
Online
{
long Tcode ;
float charge;
int period;
public:
void Register ( ) ;
void Show ( ) ;
} ;
(i) Which type of Inheritance is
shown in the above example?
ii) Write names of all the member functions accessible from Show( ) function of class Training.
iii) Wri t e name of all the
members accessible through an object of
class Training.
iv) Is the function Output( )
accessible inside the function SiteOut( )?
Justify your answer.
Q4. Consider
the following and answer the questions given below :
class Medicine
{
char Category[10];
char Date_of_manufacture[10];
char Company[20];
public:
Medicine();
void entermedicinedetails();
void showmedicinedetails();
};
class capsule:public Medicine
{
protected:
char
capsule_name[30];
char volume_lable[20];
public:
float Price;
capsules();
void entercapsuledetails();
void showcapsuledetails();
};
class Antibiotics:public Capsule
{
int Dosage_units;
char side_effects[20];
int Use_within_days;
public:
Antibiotics();
void enterdetails();
void showdetails();
};
(i) How many bytes will be
required by an object of class Medicines and an object of class Antibiotics
respectively?
(ii) Write the names of all the
member functions accessible from the object of class Antibiotics.
(iii) Write the names of all the
members accessible from member functions of class capsules.
(iv) Write names of all the
data members which are accessible from objects of class antibiotics.
Q5. Consider
the following and answer the questions given below :
class Dolls
{
char Dcode[5];
protected:
float Price;
void
CalcPrice(float);
public:
Dolls();
void DInput();
void DShow();
};
class SoftDolls:public Dolls
{
char SDName[20];
float Weight;
public:
SoftDolls();
void SDInput();
void SDShow();
};
class ElectronicDolls:public Dolls
{
char EDName[20];
char BatteryType[10];
int Batteries;
public:
ElecronicDolls();
void EDInput();
void EDShow();
};
(i) Which type of inheritance
is shown in the above example?
(ii) How many bytes will be
required by an object of the class ElectronicDolls?
(iii) Write name of all data
members accessible from member function of the classSoftDolls.
(iv) Write name of member
functions accessible an object of the class ElectronicDolls?
Q6. Consider
the following and answer the questions given below :
class
Trainer
{
{
char
TNo[5],Tname[20],specialization[10];
int Days;
int Days;
protected
:
float
Remuneratoin;
void AssignRem(float);
public:
Trainer();
void
TEntry();
void
TDisplay();
};
class Learner
{
class Learner
{
char
Regno[10],LName[20],Program[10];
protected:
int Attendance,grade;
public:
Learner();
void LEntry();
void LDisplay();
protected:
int Attendance,grade;
public:
Learner();
void LEntry();
void LDisplay();
};
class Institute : public Learner, public Trainer
{
class Institute : public Learner, public Trainer
{
char ICode[10],IName[20];
public:
Institute();
void IEntry();
void IDisplay();
Institute();
void IEntry();
void IDisplay();
};
(i) Which
type of inheritance is depicted by above example?
(ii) Identify
the member function(s) that cannot be called directly from the objects of class
Institute from the following: TEntry(), LDisplay(), IEntry()
(iii) Write
name of all member(s) accessible from member functions of class institute.
(iv) If
class institute was derived privately from class Learner and privately from
class Trainer, then name the member function(s)that could be accessed through
Objects of class Institute.
Q7. Consider the following and answer the questions given below :
class
toys
{
char tcode[5];
protected:
float price;
void
assign(float);
public:
toys();
void tentry();
void tdisplay();
};
class
softtoys : public toys
{
char stname[20];
float weight;
public:
softtoys();
void stentry();
void stdisplay();
};
class
electronictoys : public toys
{
char etname[20];
int
no_of_batteries;
public:
electronictoys();
void etentry();
void etdisplay();
};
(i) Which type of inheritance is shown in the above example?
(ii) How many bytes will be required by an object of the class
softtoys?
(iii) Write the name of all the data members accessible from member
functions of class softtoys?
(iv) Write the names of all the member functions which are
accessible from an object of class electronictoys.
No comments:
Post a Comment