Answer to Question #123839 in C++ for Remo

Question #123839
raman is a landlord with 21 acres of land and 60 lakh of other property. he has three sons having equal right on property. all three sons had 2 children each having equal rights on father property. write a c++ program with appropriate inheritance and display the property given to each children of raman
1
Expert's answer
2020-06-25T08:00:40-0400
#include <iostream>

class Raman

{

public:

  float acres = 21;

  float lakh = 60;

  void display() { std::cout << "acres: " << acres << "; " << "lakh: " << lakh << "\n"; }

};




class Son : protected Raman

{

public:

  Son()

  {

    acres /= 3;

    lakh /= 3;

  }

  void display() { std::cout << "Son:" << "\n"; Raman::display(); }

};




class Grandson :protected Son

{

public:

  Grandson()

  {

    acres /= 2;

    lakh /= 2;

  }

  void display() { std::cout << "Grandson:" << "\n"; Raman::display(); }

};

int main()

{

  Raman raman;

  std::cout << "Raman" << "\n";

  raman.display();

  Son son1, son2, son3;

  son1.display();

  son2.display();

  son3.display();

  Grandson grandson1_1, grandson1_2, grandson2_1, grandson2_2, grandson3_1, grandson3_2;

  grandson1_1.display();

  grandson1_2.display();

  grandson2_1.display();

  grandson2_2.display();

  grandson3_1.display();

  grandson3_2.display();

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS