COMPUTER SCIENCE INHERITANCE

DELHI 2005:

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

4

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?

Ans: Medicine – 40 Bytes Antibiotics Object – 118 Bytes

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

Ans:

Medicine::entermedicinedetails()
Medicine::showmedicinedetails()
Capsules::entercapsuledetails()
Capsules::showcapsuledetails()
Antibiotics::enterdetails()
Antibiotics::showdetails()

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

Ans:

Data Members:
Capsule::capsule_name[30]
Capsule::volume_lable[20]
Capsule::Price
Member Funcitons:
Medicine::entermedicinedetails()
Medicine::showmedicinedetails()
Capsule::entercapsuledetails()Capsule::showcapsuledetails()

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

Data members:
Capsule::Price


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