fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Animal
  4. {
  5. private:
  6.  
  7. string name;
  8. int age;
  9. float weight;
  10. public:
  11. void set_name(string name)
  12. {
  13. this->name=name;
  14. }
  15. void set_age(int age)
  16. {
  17. this->age=age;
  18. }
  19. void set_w(float weight)
  20. {
  21. this->weight=weight;
  22. }
  23. string get_name()
  24. {
  25. return name;
  26. }
  27. int get_age()
  28. {
  29. return age;
  30. }
  31. float get_weight()
  32. {
  33. return weight;
  34. }
  35.  
  36. void display()
  37. {
  38. cout<<this->name<<endl;
  39. cout<<this->age<<endl;
  40. cout<<this->weight<<endl;
  41.  
  42. }
  43.  
  44. };
  45. class Dog:public Animal
  46. {
  47. private:
  48. string breed;
  49. public:
  50. void set_breed(string breed)
  51. {
  52. this->breed=breed;
  53. }
  54. string get_breed()
  55. {
  56. return breed;
  57. }
  58. void display()
  59. {
  60. Animal::display();
  61.  
  62. cout<<this->breed<<endl;
  63. }
  64.  
  65. };
  66.  
  67. int main()
  68. {
  69. Dog d1;
  70. string name;
  71. int age;
  72. float weight;
  73. string breed;
  74.  
  75. cout<<"enter name"<<endl;
  76. cin>>name;
  77. d1.set_name(name);
  78. cout<<"enter age"<<endl;
  79. cin>>age;
  80. d1.set_age(age);
  81. cout<<"enter weight"<<endl;
  82. cin>>weight;
  83. d1.set_w(weight);
  84. cout<<"enter breed"<<endl;
  85. cin>>breed;
  86. d1.set_breed(breed);
  87. cout<<"attributes after inheritanc is"<<endl;
  88. d1.display();
  89. return 0;
  90. }
  91.  
  92.  
  93.  
  94.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
enter name
enter age
enter weight
enter breed
attributes after inheritanc is

-177027125
7.61606e-42