Vous êtes sur la page 1sur 6

CHENNAI PUBLIC

SCHOOL
Anna Nagar  Chennai -600 101

COMPUTER SCIENCE – INHERITANCE –WS

1) Consider the following code and answer the questions from (i) to (iv)

class Campus
{
long Id;
char City[20];
protected:
char Country[20];
public:
Campus();
void Register();
void Display();
};
class Dept : private Campus
{
long DCode[10];
char HOD[20];
protected:
double Budget;
public:
Dept();
void Enter();
void Show();
};
class Applicant : public Dept
{
long RegNo;
char Name[20];
public:
Applicant();
void Enroll();
void View();
};
i) Which type of inheritance is shown in the above example?
ii) Write the names of those member functions which are directly accessed from the objects of class
Applicant.
iii) Write the names of those data members, which can be directly accessed from the member functions of
class Applicant.
iv) Is it possible to directly call function Display() of class Campus from an object of class Dept?

2) Consider the following code and answer the questions from (i) to (iv)

class Student
{
int Class, Rno;
char Section;
protected:
Class XII Computer Science Inheritance Page 1 of 6
char SName[20];
public:
Student();
void Stentry();
void Stdisplay();
};
class Score:private Student
{
float Marks[5];
protected:
char Grade[5];
public:
Score();
void Sentry();
void Sdisplay();
};
class Report:public Score
{
float Total, Avg;
public:
char OverallGrade, Remarks[20];
Report();
void REvaluate();
void RPrint();
};
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 objects of class Report.
iii) Write the names of those member functions, which can be directly accessed from the objects of class
Report.
iv) Write the names of those data members, which can be directly accessed from the Sentry() function of
class Score.

3 Consider the following code and answer the questions from (i) to (iv)

class ITEM
{
char ICode[10];
protected:
char IName[20];
public:
ITEM();
void Enter();
void Display();
};
class SUPPLIER
{
char SCode[10];
protected:
char SName[25];
public:
SUPPLIER();
void TEnter();
Class XII Computer Science Inheritance Page 2 of 6
void TDisplay();
};
class SHOP: private SUPPLIER, public ITEM
{
char SHOPADDRESS[15],SEmail[25];
public:
SHOP();
void Enter();
void Display();
};
i) Which type of inheritance is shown in the above example?
ii) Write the names of all member functions accessible from Enter() function of class SHOP.
iii) Write the names of all the member functions accessible through an object of class SHOP.
iv) What will be the order of execution for the constructors ITEM(), SUPPLIER(), and SHOP() , when an
object of class SHOP is declared?
4 Consider the following code and answer the questions from (i) to (iv)
class FRUIT
{
int FID; // identification number
char type[20];
protected:
char Description[20];
float cost;
public:
FRUIT();
void Set_values();
void Show_values();
};
class FRESH: public FRUIT
{
char color[10];
protected:
char Agent[20];
public:
FRESH();
void Read_values();
void Display_values();
};
class DECORATIVE: protected FRUIT
{
float Dec_charges;
public:
void input();
void output();
};
i) Which type of inheritance is shown in the above example?
ii) Write the names of data members which are accessible by objects of class type DECORATIVE.
iii) Write the names of all the member functions accessible by the member functions of class FRESH.
Class XII Computer Science Inheritance Page 3 of 6
iv) How many bytes will be required by an object of class type DECORATIVE?
5) Consider the following code and answer the questions from (i) to (iv)
class stationary
{
char Type;
char Manufacturer[10];
public:
stationary();
void Read_sta_details();
void Disp_sta_details();
};
class office: public stationary
{
intno_of_types;
float cost_of_sta;
public:
void Read_off_details();
void Disp_off_details();
};
class printer: private office
{
intno_of_user;
char delivery_details[10];
public:
void Read_pri_details();
void Disp_pri_details();
};
void main()
{
printer MyPrinter;
}
i) Mention the member names, which are accessible by MyPrinter declared in main() function.
ii) What is the size of MyPrinter in bytes?
iii) Mention the names of functions accessible from the member function Read_pri_details() of class
printer.
6) Suppose we have following program:
#include <iostream.h>
#include <conio.h>
class A
{
public:
A() {cout<<"A";}
~A(){cout<<"~A";}
};
class B
{
public:
B() {cout<<"B";}
Class XII Computer Science Inheritance Page 4 of 6
~B(){cout<<"~B";}
};
class C
{
public:
C() {cout<<"C";}
~C(){cout<<"~C";}
private:
A b; B a;
};
class D
{
public:
D() {cout<<"D";}
~D(){cout<<"~D";}
};
class E:public C
{
public:
E() {cout<<"E";}
~E(){cout<<"~E";}
private:
B b; D d;
};
void main()
{
clrscr();
E e;
cout<<endl;
}
Assuming that the program compiles and runs correctly, what does it print out?
7) Consider the following declaration and answer the questions given below
class WORLD
{
int H;
protected:
int S;
public:
void INPUT(int);
void OUTPUT();
};
class COUNTRY:private WORLD
{
int T;
protected:
int U;
public:
void INDATA(int, int);
Class XII Computer Science Inheritance Page 5 of 6
void OUTDATA();
};
class STATE: public COUNTRY
{
int M;
public:
void DISPLAY(void);
};
i) Name the base class and derived class of the class COUNTRY.
ii) Name the data member(s) that can be accessed from function DISPLAY().
iii) Name the member function(s), which can be accessed from the objects of class STATE.
iv) Is the member function OUTPUT() accessible from the objects of the class COUNTRY?
8) Write a program to read and display information about employees and managers. Employee is a class
that contain – employee number, name, address and department.
Manager class contains all information of the Employee class and a list of employees working under a
manager.

The End

Class XII Computer Science Inheritance Page 6 of 6

Vous aimerez peut-être aussi