Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class animal
- {
- protected:
- int height;
- int weight;
- public:
- animal() {}
- animal(int height1, int weight1) {
- height = height1;
- weight = weight1;
- }
- void setHeight(int height1) { height = height1; }
- void getHeight() { cout << "Рост: " << height << endl; }
- void setWeight(int weight1) { weight = weight1; }
- void getWeight() { cout << "Вес: " << weight << endl; }
- bool operator==(animal& right)
- {
- return height == right.height && weight == right.weight;
- }
- friend ostream& operator << (ostream &out, const animal &point)
- {
- out << point.height << " " << point.weight;
- return out;
- }
- };
- class birds : public animal {
- private:
- string tipe;
- public:
- birds() : animal() {}
- birds(int heightS, int weightS, string tipe1) : animal(heightS, weightS) {
- tipe = tipe1;
- }
- void setTipe(int tipe1) { tipe = tipe1; }
- void getTipe() { cout << "Тип птиц: " << tipe << endl; }
- friend ostream& operator << (ostream &out, const birds &point)
- {
- out << point.height << " " << point.weight << " " << point.tipe;
- return out;
- }
- };
- class mleko : public animal {
- private:
- string klass;
- public:
- mleko() : animal() {}
- mleko(int heightS, int weightS, string klass1) : animal(heightS, weightS) {
- klass = klass1;
- }
- void setKlass(int klass1) { klass = klass1; }
- void getKlass() { cout << "Класс млекопитающих: " << klass << endl; }
- friend ostream& operator << (ostream &out, const mleko &point)
- {
- out << point.height << " " << point.weight << " " << point.klass;
- return out;
- }
- };
- class pkopyt : public animal {
- private:
- string otryad;
- public:
- pkopyt() : animal() {}
- pkopyt(int heightS, int weightS, string otryad1) : animal(heightS, weightS) {
- otryad = otryad1;
- }
- void setOtryad(string otryad1) { otryad = otryad1; }
- void getOtryad() { cout << "Отряд парнокопытных: " << otryad << endl; }
- friend ostream& operator << (ostream &out, const pkopyt &point)
- {
- out << point.height << " " << point.weight << " " << point.otryad;
- return out;
- }
- };
- int main(int argc, char* argv[])
- {
- animal arr[3];
- arr[0] = birds(0, 0, "asdf");
- arr[1] = mleko(0, 0, "zcxv");
- arr[2] = pkopyt(2, 2, "eqwer");
- cout << "birds:\n" << arr[0] << endl;
- cout << "mlekopitaushie:\n" << arr[1] << endl;
- cout << "parnokopytnie:\n" << arr[2] << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement