COMPUTER SCIENCE INHERITANCE

DELHI 2008:

2.d) Answer the questions (i) to(iv) based on the following code :

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 DShow();
};
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?

Ans: Hierarchical Inheritance. Since the sub classes are derived from a single base class(Dolls).

(ii) How many bytes will be required by an object of the class ElectronicDolls ?

Ans: 41 Bytes (Explonation: The memory will be reserved as follows:

char Dcode[5]; //5 Bytes
float Price; //4 Bytes
char EDName[20]; //20 Bytes
char BatteryType[10]; //10 Bytes
int Batteries; //2 Bytes
Total = 41 Bytes )

iii) Write name of all data members accessible from member function of the class SoftDolls.

Ans: Dolls::Price, SoftDolls:: SDName, SoftDolls::Weight

(iv) Write name of member functions accessible an object of the class ElectronicDolls?

Ans: ElectronicDolls::EDInput( ), ElectronicDolls::EDShow( ), Dolls::DInput( ), Dolls::DShow( )

OUTSIDE DELHI 2008:

2.d) Answer the questions (i) to(iv) based on the following code :

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:
ElecronicToys();
void ETEntry();
void ETDisplay();
};

(i) Which type of Inheritance is shown in the above example?

Ans: Hierarchical Inheritance. Since the sub classes are derived from a single base class(Dolls).

(ii) How many bytes will be required by an object of the class SoftToys ?

Ans: 33 Bytes(Explonation: The memory will be reserved as follows:

char Tcode[5]; //5 Bytes
float Price; //4 Bytes
char STName[20]; //20 Bytesfloat Weight; // 4 Bytes Total = 33 Bytes)

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )