Advertisement
alexx876

Untitled

Mar 29th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class animal
  6. {
  7. protected:
  8.     int height;
  9.     int weight;
  10. public:
  11.     animal() {}
  12.     animal(int height1, int weight1) {
  13.         height = height1;
  14.         weight = weight1;
  15.     }
  16.  
  17.     void setHeight(int height1) { height = height1; }
  18.     void getHeight() { cout << "Рост: " << height << endl; }
  19.     void setWeight(int weight1) { weight = weight1; }
  20.     void getWeight() { cout << "Вес: " << weight << endl; }
  21.  
  22.     bool operator==(animal& right)
  23.     {
  24.         return height == right.height && weight == right.weight;
  25.     }
  26.  
  27.     friend ostream& operator << (ostream &out, const animal &point)
  28.     {
  29.         out << point.height << "   " << point.weight;
  30.         return out;
  31.     }
  32. };
  33.  
  34. class birds : public animal {
  35. private:
  36.     string tipe;
  37. public:
  38.     birds() : animal() {}
  39.     birds(int heightS, int weightS, string tipe1) : animal(heightS, weightS) {
  40.         tipe = tipe1;
  41.     }
  42.     void setTipe(int tipe1) { tipe = tipe1; }
  43.     void getTipe() { cout << "Тип птиц: " << tipe << endl; }
  44.  
  45.     friend ostream& operator << (ostream &out, const birds &point)
  46.     {
  47.         out << point.height << "   " << point.weight << "   " << point.tipe;
  48.         return out;
  49.     }
  50. };
  51.  
  52. class mleko : public animal {
  53. private:
  54.     string klass;
  55. public:
  56.     mleko() : animal() {}
  57.     mleko(int heightS, int weightS, string klass1) : animal(heightS, weightS) {
  58.         klass = klass1;
  59.     }
  60.     void setKlass(int klass1) { klass = klass1; }
  61.     void getKlass() { cout << "Класс млекопитающих: " << klass << endl; }
  62.  
  63.     friend ostream& operator << (ostream &out, const mleko &point)
  64.     {
  65.         out << point.height << "   " << point.weight << "   " << point.klass;
  66.         return out;
  67.     }
  68. };
  69.  
  70. class pkopyt : public animal {
  71. private:
  72.     string otryad;
  73. public:
  74.     pkopyt() : animal() {}
  75.     pkopyt(int heightS, int weightS, string otryad1) : animal(heightS, weightS) {
  76.         otryad = otryad1;
  77.     }
  78.     void setOtryad(string otryad1) { otryad = otryad1; }
  79.     void getOtryad() { cout << "Отряд парнокопытных: " << otryad << endl; }
  80.  
  81.     friend ostream& operator << (ostream &out, const pkopyt &point)
  82.     {
  83.         out << point.height << "   " << point.weight << "   " << point.otryad;
  84.         return out;
  85.     }
  86. };
  87.  
  88.  
  89.  
  90. int main(int argc, char* argv[])
  91. {
  92.  
  93.     animal arr[3];
  94.     arr[0] = birds(0, 0, "asdf");
  95.     arr[1] = mleko(0, 0, "zcxv");
  96.     arr[2] = pkopyt(2, 2, "eqwer");
  97.  
  98.     cout << "birds:\n" << arr[0] << endl;
  99.     cout << "mlekopitaushie:\n" << arr[1] << endl;
  100.     cout << "parnokopytnie:\n" << arr[2] << endl;
  101.  
  102.     system("pause");
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement