Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Animal
  6.  
  7. {
  8.  
  9. private:
  10.  
  11. int age; //age of the animal
  12.  
  13. protected:
  14.  
  15. float weight; //weight of animal
  16.  
  17. public:
  18.  
  19. Animal() { age = 0; weight = 0.0; }
  20.  
  21. void setAge(int x) {
  22.  
  23. age = x;
  24.  
  25. }
  26.  
  27. void setWeight(int x) {
  28.  
  29. weight = x;
  30.  
  31. }
  32.  
  33. int getAge() { return age; }
  34.  
  35. int getWeight() { return weight; }
  36.  
  37. };
  38.  
  39. class Cat : public Animal
  40.  
  41. {
  42.  
  43. private:
  44.  
  45. int age;
  46.  
  47. int legs;
  48.  
  49. protected:
  50.  
  51. float weight2;
  52.  
  53. public:
  54.  
  55. Cat() {
  56.  
  57. weight2 = 0.0; legs = 4;
  58.  
  59. }
  60.  
  61. void setLegs(int x) {
  62.  
  63. legs = x;
  64.  
  65. }
  66.  
  67. int getLegs() { return legs; }
  68.  
  69. int getWeight2() { return weight2; }
  70.  
  71. };
  72.  
  73. class snake : public Animal
  74.  
  75. {
  76.  
  77. private:
  78.  
  79. int age2;
  80.  
  81. bool IsPoinsonous;
  82.  
  83. public:
  84.  
  85. snake() { age2 = 0; IsPoinsonous = 0; }
  86.  
  87. void setIsPoisonous(int x) {
  88.  
  89. IsPoinsonous = x;
  90.  
  91. }
  92.  
  93. int getIsPoinsonpus() { return IsPoinsonous; }
  94.  
  95. int getAge2() { return age2; }
  96.  
  97. };
  98.  
  99. int main()
  100.  
  101. {
  102.  
  103. Animal x;
  104.  
  105. cout << "Initial value for x: " << endl;
  106.  
  107. cout << "Age = " << x.getAge() << " Weight = " << x.getWeight() << endl;
  108.  
  109. x.setAge(10);
  110.  
  111. x.setWeight(20);
  112.  
  113. cout << "Modified value for x: " << endl;
  114.  
  115. cout << "Age = " << x.getAge() << " Weight = " << x.getWeight() << endl;
  116.  
  117.  
  118.  
  119. Cat y;
  120.  
  121. cout << "Initial value for y: " << endl;
  122.  
  123. cout << "Age = " << y.getAge() << " Weight = " << y.getWeight() << endl;
  124.  
  125. y.setAge(12);
  126.  
  127. y.setWeight(17);
  128.  
  129. cout << "Modified value for y: " << endl;
  130.  
  131. cout << "Age = " << y.getAge() << " Weight = " << y.getWeight() << " Weight2 = " << y.getWeight2() << endl;
  132.  
  133.  
  134.  
  135. snake z;
  136.  
  137. cout << "Initial value for z: " << endl;
  138.  
  139. cout << "Age = " << z.getAge() << "Weight = " << z.getWeight() << endl;
  140.  
  141. z.setAge(14);
  142.  
  143. z.setWeight(23);
  144.  
  145. cout << "Modified value for z: " << endl;
  146.  
  147. cout << "Age = " << z.getAge() << " Weight = " << z.getWeight() << " Age2 = " << z.getAge2() << endl;
  148.  
  149. system("pause");
  150.  
  151. return 0;
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement