Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Animals { //клас тварин
- protected: //тип для доступу у похідних класах
- float weight; //маса
- int lifetime; //тривалість життя
- public:
- Animals() {} //пустий конструктор
- Animals(float a, int b) : weight(a), lifetime(b) {} //констуктор ініціалізації списком
- virtual void get() { //віртуальна функція для друкування даних
- cout << "Info about animal:" << endl;
- cout << "\tweight: " << weight << endl;
- cout << "\tlifetime: " << lifetime << endl << endl;
- }
- virtual void set() { //віртуальна функція для встановлення даних
- cout << "Enter info about animal:" << endl;
- cout << "\tweight: ";
- cin >> weight;
- cout << "\tlifetime: ";
- cin >> lifetime;
- cout << endl;
- }
- };
- class Mammals : public Animals { //клас ссавці на основі тварин
- protected: //тип для доступу у похідних класах
- string coatColor; //колір шерсті
- public:
- Mammals() {} //пустий констуктор
- Mammals(float a, int b, string c) : Animals(a, b), coatColor(c) {} //констуктор ініціалізації списком (ініціалізується також клас тварин)
- virtual void get() { //віртуальна функція для друкування даних
- cout << "Info about mammals:" << endl;
- cout << "\tweight: " << weight << endl;
- cout << "\tlifetime: " << lifetime << endl;
- cout << "\tcoat color: " << coatColor << endl << endl;
- }
- virtual void set() { //віртуальна функція для встановлення даних
- cout << "Enter info about mammals:" << endl;
- cout << "\tweight: ";
- cin >> weight;
- cout << "\tlifetime: ";
- cin >> lifetime;
- cout << "\tcoat color: ";
- cin >> coatColor;
- cout << endl;
- }
- };
- class Artiodactylas : public Mammals { //клас парнокопитні на основі ссавців
- float runningSpeed; //швидкість пересування
- public:
- Artiodactylas() {} //пустий констуктор
- Artiodactylas(float a, int b, string c, float d) : Mammals(a, b, c), runningSpeed(d) {} //констуктор ініціалізації списком (ініціалізується також клас ссавців)
- void get() { //функція для друкування даних
- cout << "Info about artiodactylas:" << endl;
- cout << "\tweight: " << weight << endl;
- cout << "\tlifetime: " << lifetime << endl;
- cout << "\tcoatColor: " << coatColor << endl;
- cout << "\trunning speed: " << runningSpeed << endl << endl;
- }
- void set() { //функція для введення даних
- cout << "Enter info about artiodactylas:" << endl;
- cout << "\tweight: ";
- cin >> weight;
- cout << "\tlifetime: ";
- cin >> lifetime;
- cout << "\tcoatColor: ";
- cin >> coatColor;
- cout << "\trunning speed: ";
- cin >> runningSpeed;
- cout << endl;
- }
- };
- class Birds : public Animals { //клас птиць на основі тварин
- string featherColor; //колір пір'я
- float flightSpeed; //швидкість польоту
- public:
- Birds() {} //пустий констуктор
- Birds(float a, int b, string c, float d) : Animals(a, b), featherColor(c), flightSpeed(d) {} //конструктор ініціалізації списком (ініціалізується також клас тварин)
- void get() { //фукнція для виведення даних
- cout << "Info about bird:" << endl;
- cout << "\tweight: " << weight << endl;
- cout << "\tlifetime: " << lifetime << endl;
- cout << "\tfeather color: " << featherColor << endl;
- cout << "\tflight speed: " << flightSpeed << endl << endl;
- }
- void set() { //функція для введення даних
- cout << "Enter info about bird:" << endl;
- cout << "\tweight: ";
- cin >> weight;
- cout << "\tlifetime: ";
- cin >> lifetime;
- cout << "\tfeather color: ";
- cin >> featherColor;
- cout << "\tflight speed: ";
- cin >> flightSpeed;
- cout << endl;
- }
- };
- int main() {
- Animals* a = new Mammals(50, 25, "black"); //інаціалізація за констуктором класу Mammals (ссавці)
- a->get(); //функція класу Mammals (ссавці)
- Animals* b = new Artiodactylas(55, 30, "gray", 5); //інаціалізація за констуктором класу Artiodactylas (парнокопитні)
- b->get(); //функція класу Artiodactylas (парнокопитні)
- Animals* c = new Birds(1, 5, "red", 15); //інаціалізація за констуктором класу Birds (птиці)
- c->get(); //функція класу Birds (птиці)
- delete a, b, c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment