Advertisement
Mite123

Random zivotini

May 26th, 2020
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. class Animal {
  5. protected:
  6.     int height;
  7.     int weight;
  8.     int width;
  9. public:
  10.     Animal() {};
  11.     Animal(int height, int weight,int width) {
  12.         this->height = height;
  13.         this->weight = weight;
  14.         this->width = width;
  15.     }
  16.    
  17.     virtual void print() = 0;
  18. };
  19. class Mammals:public Animal {
  20. private:
  21.    
  22.     char name[20];
  23. public:
  24.     Mammals(){}
  25.     Mammals(char *name ,int weight, int height, int width) :Animal(weight, height, width) {
  26.         strcpy(this->name, name);
  27.     }
  28.    
  29.     void print() {
  30.         cout << "Mammal: ";
  31.         for (int i = 0; i < strlen(name); i++) {
  32.             cout << name[i];
  33.         }
  34.         cout << "\n";
  35.         cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
  36.     }
  37.     ~Mammals(){}
  38. };
  39. class Birds:public Animal {
  40. private:
  41.    
  42.     char name[20];
  43. public:
  44.     Birds() {}
  45.     Birds(char *name,int weight, int height,int width):Animal(weight,height,width) {
  46.         strcpy(this->name, name);
  47.     }
  48.     void print() {
  49.         cout << "Bird: ";
  50.         for (int i = 0; i < strlen(name); i++) {
  51.             cout << name[i];
  52.         }
  53.         cout << "\n";
  54.         cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
  55.     }
  56.     ~Birds(){}
  57. };
  58.  
  59. class Fish:public Animal {
  60. private:
  61.  
  62.     char name[20];
  63. public:
  64.     Fish() {
  65.        
  66.     }
  67.     Fish(char *name ,int weight, int height, int width) :Animal(weight, height, width) {
  68.        
  69.         strcpy(this->name, name);
  70.     }
  71.     void print() {
  72.         cout << "Fish: ";
  73.         for (int i = 0; i < strlen(name); i++) {
  74.             cout << name[i];
  75.         }
  76.         cout << "\n";
  77.         cout << "Weight: " << weight << "\nHeight: " << height << "\nWidth: " << width << endl;
  78.     }
  79.     ~Fish(){}
  80. };
  81. int main() {
  82.     /*char name[20];
  83.     int weight, height, width;  
  84.     cin >> name >> weight >> height >> width; ova e za vnesuvanje ako sakas */
  85.     Fish a((char*)"Kit",1200,10,15);// char od prede za kastiranje od string vo char
  86.     a.print();             
  87.     Birds b((char*)"Ptica", 2, 3, 4);// char od prede za kastiranje od string vo char
  88.     Mammals c((char*)"Monkey", 5, 6, 7);// char od prede za kastiranje od string vo char
  89.     b.print();
  90.     c.print();
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement