Advertisement
Josif_tepe

Untitled

Jan 20th, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Animal {
  5. private:
  6.     string name;
  7.     int age, weight;
  8.    
  9. public:
  10.     Animal() {}
  11.     Animal(string _name, int _age, int _weight) {
  12.         name = _name;
  13.         age = _age;
  14.         weight = _weight;
  15.     }
  16.     Animal(const Animal & tmp) {
  17.         name = tmp.name;
  18.         age = tmp.age;
  19.         weight = tmp.weight;
  20.     }
  21.    
  22.     string get_name() {
  23.         return name;
  24.     }
  25.     void set_name(string _name) {
  26.         name = _name;
  27.     }
  28. };
  29.  
  30. class Cat : public Animal {
  31. private:
  32.     string breed;
  33.     string color;
  34.  
  35. public:
  36.     Cat() : Animal() {}
  37.     Cat(string _name, int _age, int _weight, string _breed, string _color) : Animal(_name, _age, _weight) {
  38.         breed = _breed;
  39.         color = _color;
  40.     }
  41.     Cat(const Cat & tmp) : Animal(tmp) {
  42.         breed = tmp.breed;
  43.         color = tmp.color;
  44.     }
  45.    
  46.     void print() {
  47.         cout << get_name() << " " << breed << " " << color << endl;
  48.     }
  49. };
  50. int main()
  51. {
  52.     Cat c("Garfield", 12, 150, "orange", "orange");
  53.     c.print();
  54.  
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement