Advertisement
Josif_tepe

Untitled

Dec 12th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Animal {
  6. private:
  7.     char * ime;
  8.     int godini;
  9.     bool pitomo;
  10.    
  11. public:
  12.     Animal() {}
  13.     Animal(char * _ime, int _godini, bool _pitomo) {
  14.         ime = new char[strlen(ime)];
  15.         strcpy(ime, _ime);
  16.         godini = _godini;
  17.         pitomo = _pitomo;
  18.     }
  19.     ~Animal() {
  20.         delete[] ime;
  21.     }
  22.    
  23.     char * get_ime() {
  24.         return ime;
  25.     }
  26.     int get_godini() {
  27.         return godini;
  28.     }
  29.     bool get_pitomo() {
  30.         return pitomo;
  31.     }
  32. };
  33.  
  34. class Cat : public Animal {
  35. private:
  36.     char * vid_na_macka;
  37.    
  38. public:
  39.     Cat() : Animal() {
  40.        
  41.     }
  42.    
  43.     Cat(char * _ime, int _godini, bool _pitomo, char * _vid_na_macka) : Animal(_ime, _godini, _pitomo) {
  44.         vid_na_macka = new char[strlen(_vid_na_macka)];
  45.         strcpy(vid_na_macka, _vid_na_macka);
  46.     }
  47.     ~Cat() {
  48.         delete[] vid_na_macka;
  49.     }
  50.    
  51.     char * get_vid_na_macka() {
  52.         return vid_na_macka;
  53.     }
  54.    
  55.    
  56. };
  57. int main()
  58. {
  59.  
  60.     Cat c("tom", 5, false, "ulicna");
  61.     cout << c.get_godini() << endl;
  62.     cout << c.get_ime() << endl;
  63.     cout << c.get_vid_na_macka() << endl;
  64.     return 0;
  65.  
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement