Wednesday

Important Questions of Inheritance - CSE- Class 12 (Part 2)

 Question 11:

Consider the following class State: All India 2014C

class State 
{
protected:
int tp: //no. of tourist places 
public:
State()
{
tp = 0;
}
void inctp()
{
tp++;
}
int gettp()
{
return tp;
}
}:

Write a code in C++ to publically derive another class ‘District’ with the following additional members derived in the public visibility’mode.
Data Members
• distname – char (50)
• population – long
Member functions
• dinput() — To enter distname and population.
• doutput() — To display distname and population on screen.
Answer:

class State
{
protected:
int tp; //No. of tourist places public: 
state()
{
tp = 0;
}
void inctp() 
{
tp++;
int gettp()
{
return tp;
}
};
class District : public State
{
public:
char distname[50]; 
long population;
District()
{
distname = " "; 
population = 0;
{
void dinput!)
{
cout<<"Enter distname and population”; 
cin>>distname>>population;
}
void doutput()
{
cout<<"Di stname: "<<distname; cout<<"Population:"
}
};

Question 12:
Consider the following C + + code and answer the questions from (i) to (iv). All India 2013

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]; 
ResultO() .
void Rcalculate(); 
void RdisplayO;
};

(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 the names of those data members, which can be directly accessed from the Mentry() function of class Marks.

Answer:

(i) Multilevel Inheritance
(ii) FinalGrade, Comments [20]
(iii) Rcalculate( ), Rdisplay( ),
Mentry( ), Mdisplay( )
(iv) M[5], Grade[5], Name[20]

Question 13:
Consider the following C + + code and answer the questions from (i) to (iv). Delhi 2013

class Student 
{
int Class, Rno; 
char Section; .
protected:
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 the 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.

Answer:

(i) Multilevel Inheritance
(ii)  OverallGrade, Remarks[20].
(iii) REvaluate( ), RPrint( ), Sentry( ),
Sdisplay( ).
(iv) Marks[5], Grade[5], SName[20]

Question 14:
Consider the following and answer the questions given below: Delhi 2013C

class ITEM 
{
char ICodet10]; 
protected:
char IName[20]; 
public:
ITEM(); 
void Enter(); 
void Display();
}:
class SUPPLIER 
{
char SCode[10];
protected:
char SName[25];
 public:
SUPPLIER(): 
void TEnter(); 
void TDisplay();
}:
class SHOP : private SUPPLIER,
public ITEM
{
char SH0PADDRESSC[15],SEmai1[25]; 
public:
SHOP(); 
void Enter(); 
void Display();
}:

(i) Which type of inheritance is shown in the above example?
(ii) Write the name of all the 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?

Answer:

(i) Multiple Inheritance
(ii) TEnter( ) and TDisplay( ) of class SUPPLIER Enter( ) and Display( ) of both class ITEM and SHOP
(iv) Enter( ) and Display( ) of both class SHOP and ITEM.
(iv) SUPPLIER() → ITEM( ) → SHOP( )

Question 15:
Answer the questions (i) to (iv) based on the following: All India 2012

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 the 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.

Answer:

(i) Hierarchical Inheritance
(ii) location[20], area, sale
(iii) Enter( ), Register() and Show( ) of both
class FACTORY and COMPANY
(iv) Data Members
None
Member Functions
Input( ), Output( )

Question 16:
Answer the questions (i) to (iv) based on the following: Delhi 2012

class ORGANISATION 
{
char Address[20]; 
double budget,Income; 
protected:
void Compute(); 
public:
ORGANISATION(); 
void Get(); 
void Show();
};
class WORKAREA : public ORGANISATION 
{
char Address[20]; 
int staff; 
protected: 
double pay;
void Calculate(); 
public:
WORKAREA(); 
void Enter(); 
void Display();
};
class SHOWROOM : private ORGANISATION
{
char Address[20]; 
float Area; 
double Sale; 
public:
SHOWROOM();
void Enter!(); 
void Show();
};

(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 SHOWROOM.
(iii) Write the names of the member functions, which are accessible from objects belonging to class WORKAREA.
(iv) Write the names of all the members, which are accessible from objects of class SHOWROOM.

Answer:

(i) Hierarchical Inheritance
(ii) Address[20], Area, Sale
(iii) Enter( ), Display) ), Get( ), Show( )
(iv) Data Members
None
Member Functions
Enter( ), Show( )

Question 17:
Answer the questions (i) to (iv) based on the following: Delhi 2011

class Student
{
int Rno; 
char name[20]; 
float Marks; 
protected:
void Result(); 
public:
Student(); 
void Register();
void Display ();
};
class Faculty 
{
long Fcode; 
char Fname[20]; 
protected: 
float Pay; 
public:
Faculty();
void Enter(); 
void Show();
};
class Course : public Student,
private Faculty
{
long CCode[10]; 
char CourseName[50]; 
char StartDate[8],EndDate[8]; 
public:
Course();
void Commerce();
void CDetai1();
};

(i) Which type of inheritance is illustrated in the above C++ code?
(ii) Write the names of the data members, which is/are accessible from the member function Commerce of class Course.
(iii) Write the name of all the member functions, which are accessible from object of class Course.
(iv) Write the name of all the member function’s, which are accessible from object of class Faculty.

Answer:

(i) Multiple Inheritance
(ii) CCode[10], CourseName[50], StartDate[8], EndDate[8], Pay
(iii) Register( ), Display) ), Commerce) ), CDetail()
(iv) Enter( ), Show( )

Question 18:
Answer the questions (i) to (iv) based on the following: All India 2011

class Student
{
int Roll no; 
char Sname[20]; 
float Marksl; 
protected:
void Result(); 
public:
Student(); 
void Enroll() ; 
void Display!);
}:
class Teacher
{
long Tcode;
char Tname[20]; 
protected:
float Salary; 
public:
Teacher();
void Enter(); 
void Show();
}:
class Course : public Student,
private Teacher
{
long CCode[10]; 
char CourseName[50];
char StartDate[8]; 
char EndDate[8]; 
public:
Course(); 
void Commerce(); 
void CDetail();
}:

(i) Write the name of all the member functions, which are accessible from object of class Course.
(ii) Write the name of the data members, which is/are accessible from the member function Commerce of class Course.
(iii) Write the name of all the member functions, which are accessible from object of class Teacher.
(iv) Which type of inheritance is illustrated in the above C++ code?

Answer:

(i) Enroll( ), Display) ), Commerce) ),
CDetail) )
(ii) CCodeflO], CourseName[50], StartDate[8], EndDate[8], Salary
(iii) Enter(), Show()
(iv) Multiple Inheritance

Question 19:
Answer the questions (i) to (iv) based on the following: All India 2010

class Director 
{
long DID; 
char Name[20]; 
protected:
char Description[40]: 
void Allocate(); 
public:
Director();
void Assign();
void Show();
}: 
class Factory : public Director
{
int FID;
char Address[20]; 
protected: 
int NOE: 
public:
Factory();
void Input(); 
void Output()
}:
class ShowRoom : private Factory
{
int SID: 
char City[20]; 
public:
ShowRoom(); 
void Enter();
void Display!
}:

(i) Which type of inheritance out of the following is illustrated in the above C++ code?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of data members, which are accessible by objects of class type ShowRoom.
(iii) Write the name of all member functions, which are accessible by objects of class type ShowRoom.
(iv) Write the names of all members, which are accessible from member function of class Factory.

Answer:

(i) Multilevel Inheritance
(ii) None
(iii) Enter(), Display()
(iv) Data Members
FID, Address[20], NOE, Description[40]
Member Functions
Input(), Output(), Assign(), Show(), Allocate()

Question 20:
Answer the questions (i) to (iv) based on the following: Delhi 2010

class Chairperson 
{
long CID;
//Chairperson Identification Number
char Cname[20];
protected:
char Description[40]: 
void Allocate(); 
public:
Chairperson(); 
void Assign(); 
void Show();
}:
class Director 
{
char profile[30];
public:
Director();
vateFactory();
voidlnput();
void Output();
}:
class Company : private Chairperson, public Director
{
int CID; //Company ID
char City[20], Country[20]; 
public:
Company(); 
void Enter(); 
void Display();
}:

(i) Which type of inheritance out of the following is illustrated in the above C++ code?
• Single Level Inheritance
• Multilevel Inheritance
• Multiple Inheritance
(ii) Write the names of data members, which are accessible by objects of class type Company.
(iii) Write the name of all member functions, which are accessible by objects of class type Company.
(iv) Write the names of all members, which are accessible from member functions of class Director.

Answer:

(i) Multiple Inheritance
(ii) None
(iii) Enter(), Display(), Input(), Output()
(iv) Data Members
DID, Dname[20], profile[30]
Member functions
Input(), Output()

Question 21:
Answer the questions (i) to (iv) based on the following: Delhi 2009C

class QUALITY 
{
private:
char Material [30]; 
float Thickness; 
protected:
char Manufacturer[20]; 
public:
QUALITY(); 
void Reading(); 
void Printing(); 
};
class QUANTITY : public 
QUALITY
long Order; 
protected: 
int Stock; 
public:
QUANTITY(); 
void Read_Data(); 
void Print_Data();
};
class FABRIC : public QUANTITY 
{
int Fabric_code, Cost; 
public;
FABRIC(); 
void Read(); 
void Show();
};

(i) Write the data members that are accessible by an object of type class FABRIC.
(ii) What type of inheritance is illustrated in the above example?
(iii) Write the names of all the members that can be accessed by the member functions of class FABRIC.
(iv) How many bytes will be required by an object of type FABRIC?

Answer:

(i) None
(ii) Multi Level Inheritance
(iii) Data Members
Fabric_code, Cost, Stock, Manufacturer[20]
Member Functions
Read(), Show(),Read_Data( ), Print_Data( ), Reading)), Printing))
(iv) 64 Bytes

Question 22:
Answer the questions (i) to (iv) based on the following: Delhi 2009

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 above example?
(ii) Write names of all member functions accessible from Show( ) function of class Training.
(iii) Write names of all members accessible through an object of class Training.
(iv) Is function Output() is accessible in function SiteOut()? Justify your answer.

Answer:

(i) Multiple Inheritance
(ii) Register(), Show(), Input(), Output(), Siteln(), SiteOut()
(iii) Data Members None Member Functions Register(), Show(), Input(), Output()
(iv) Yes, it can be accessed by using the object of FacetoFace class, because it is a public member.

Question 23:
Answer the questions (i) to (iv) based on the following; All India 2009

class Regular
{
char SchoolCode[10]; 
public:
void InRegular(); 
void OutRegular();
};
class Distance
{
char StudyCenter[5]; 
public:
void InDistance();
void OutDistance!);
};
class Course : public Regular,
private Distance
{
char Code[5]; 
float Fees; 
int Duration; public:
void InCourse();
void OutCourse();
}:

(i) Which type of inheritance is shown in above example?
(ii) Write names of all member functions accessible from OutCourse( ) function of class Course.
(iii) Write names of all members accessible through an object of class Course.
(iv) Is function InRegular( ) is accessible in function InDistance()? Justify your answer.

Answer:

(i) Multiple Inheritance
(ii) InCourse(), Outcourse(), InDistance(), OutDistance(), InRegular(), OutRegular()
(iii) Data Members None Member Functions InCourse(), OutCourse(), InRegular(), OutRegular()
(iv) Yes, it can be accessed by using.the object of class Regular because it is a public member.

0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.