Josif_tepe

Untitled

Jul 10th, 2025
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Animal {
  5. protected:
  6.     string tip;
  7.     string ime;
  8.     bool masko;
  9. public:
  10.     Animal() {}
  11.     Animal(string _tip, string _ime, bool _masko) {
  12.         tip = _tip;
  13.         ime = _ime;
  14.         masko = _masko;
  15.     }
  16.     Animal(const Animal & tmp) {
  17.         tip = tmp.tip;
  18.         ime = tmp.ime;
  19.         masko = tmp.masko;
  20.     }
  21.    
  22.     virtual void print() {
  23.         cout << "Animal: " << tip << " " << ime << " " << masko << endl;
  24.     }
  25.    
  26.    
  27. };
  28.  
  29. class Cat : public Animal {
  30. protected:
  31.     string rasa;
  32.     int godini;
  33. public:
  34.     Cat() : Animal() {
  35.        
  36.     }
  37.    
  38.     Cat(string _tip, string _ime, bool _masko, string _rasa, int _godini) : Animal(_tip, _ime, _masko) {
  39.         rasa = _rasa;
  40.         godini = _godini;
  41.     }
  42.    
  43.     Cat(const Cat & tmp) : Animal(tmp) {
  44.         rasa = tmp.rasa;
  45.         godini = tmp.godini;
  46.     }
  47.    
  48.     virtual void print() override {
  49.         Animal::print();
  50.         cout << rasa << " " << godini << endl;
  51.     }
  52.    
  53. };
  54.  
  55. int main() {
  56.     Animal * a = new Cat("macka", "Mila", false, "british shorthair", 1);
  57.    
  58.     a->print();
  59.    
  60.     return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment