Skip to content
Question of 97

Q.Answer the questions

(i) to
(iv) based on the following: class Ground { int Rooms; protected: void Put(); public: void Get(); }; class Middle : private Ground { int Labs; public: void Take(); void Give(); }; class Top : public Middle { int Roof; public: void In(); void Out(); }; void main() { Top T; }
(i) Which type of Inheritance out of the following is illustrated in the above example? Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the members, which are directly accessible by the member function Give() of class Middle.
(iii) Write the names of all the members, which are directly accessible by the member function Out() of class Top.
(iv) Write the names of all the members, which are directly accessible by the object T of class Top declared in the main() function.
(OR)
Consider the following class HeadQuarter class HeadQuarter { int Code; char Des[20]; protected : char Address[40]; public: void Get(){cin>>Code;gets(Des);gets(Address);} void Put(){cout<<Code<<Des<<Address<<endl;} }; Write a code in C++ to protectedly derive another class FrontOffice from the base class HeadQuarter with following members. Data Members Location of type character of size 10 Budget of type double Member Functions A constructor function to assign Budget as 100000 Assign() to allow user to enter Location and Budget Display() to display Location and Budget
CBSECBSE Class XII Board 2019Subjective· 4mImportance★★★★★est
0% · 0/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): the example is multilevel inheritance; visibility of members through the chain depends on the access specifiers, giving the accessible-member lists below. Part (b): a protectedly-derived FrontOffice class with the required data members, a constructor, Assign() and Display().

Part (a)

The chain is Ground → Middle (private derivation) → Top (public derivation).

(i) Type of inheritance: one class derived from another which is derived from a third → Multilevel Inheritance.

(ii) Members directly accessible inside Give() of Middle:

  • Middle's own members: Labs, Take(), Give().
  • Inherited from Ground (private derivation): Ground's public Get() and protected Put() become private members of Middle, so they are accessible within Middle's own methods.
  • Ground's private Rooms is never accessible. → Labs, Take(), Give(), Get(), Put().

(iii) Members directly accessible inside Out() of Top:

  • Top's own members: Roof, In(), Out().
  • Inherited from Middle (public derivation): Middle's public Take(), Give() remain accessible; Middle's private Labs is not.
  • Get()/Put() had become private in Middle, so they are not inherited-accessible in Top. → Roof, In(), Out(), Take(), Give().

(iv) Members accessible to object T of Top in main():

An object can use only public members. Top's public members are In(), Out(); through public derivation Middle's public Take(), Give() are also public in Top. Everything from Ground is private in Middle, hence unavailable. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.