CBSE Computer Science - Revision Tour(Solved)

CBSE Guess > eBooks > Class XII > CBSE Computer Science inheritane Solved Revision Tour By Mr. Ravi Kiran

COMPUTER SCIENCE INHERITANCE

Previous Index Next

OUTSIDE DELHI 2005:

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

class Drug
{ char Category[10];
char Date_of_manufacture[10];
char Company[20];
public:
Medicines();
void enterdrugdetails();
void showdrugdetails();
};
class tablet:public Drug
{
protected:
char tablet_name[30];
char volume_lable[20];
public:
float Price;
Tablet();
void entertabletdetails();
void showtabletdetails();
};
class PainReliever:public Tablet
{ int Dosage_units;
char side_effects[20];
int Use_within_days;
public:
PainReliever();
void enterdetails();
void showdetails();
};

(i) How many bytes will be required by an object of class Drug and an object of class PainReliever respectively?

Ans:

Drug Object - 40 Bytes
Pain Reliever – 118 Bytes

(ii) Write the names of all the member functions accessible from the object of class PainReliever.

Ans:

Drug::enterdrugdetails()
Drug::void showdrugdetails()
Tablet::entertabletdetails()
Tablet::showtabletdetails()
PainReliever::enterdetails()
PainReliever::showdetails()

(iii) Write the names of all the members accessible from member functions of class Tablet.

Ans:

Data Members:
Tablet::tablet_name[30];
Tablet::volume_lable[20];
Tablet::Price;
Member Functions:
Drug::enterdrugdetails()
Drug::showdrugdetails()
Tablet::entertabletdetails()
Tablet::showtabletdetails()

(iv) Write names of all the data members which are accessible from objects of class PainReliever.

Ans: Data Members: Tablet::Price


Previous Index Next

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