Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- class Pet {
- protected:
- string name;
- public:
- Pet(string s) {
- name = s;
- }
- Pet() {
- }
- virtual string Sound() {
- return "?";
- }
- };
- class Homa : public Pet {
- public:
- int action;
- Homa(string s, int n) :Pet(s) {
- action = n;
- }
- string Action() {
- if (action == 1) {
- string a = "Хомяк спит";
- return a;
- }
- if (action == 2) {
- string a = "Хомяк бегает в колесе";
- return a;
- }
- }
- string Sound() override{
- return "*Шумные звуки Хомяка*";
- }
- void sast() {
- int n;
- cout << "1 or 2 "; cin >> n;
- action = n;
- }
- };
- class Popug : public Pet {
- public:
- int action;
- Popug(string s, int n) :Pet(s) {
- action = n;
- }
- string Action() {
- if (action == 1) {
- string a = "Попугай отдыхает\n";
- return a;
- }
- if (action == 2) {
- string a = "Попугай летает по комнате\n";
- return a;
- }
- if (action == 3) {
- string a = "Попугай звенит в колокольчик \n";
- return a;
- }
- }
- string Sound() override {
- return "Нерешительный Попугай " + this->name + " знает слишком много слов и не может выбрать";
- }
- void sast() {
- int n; cout << "1 or 2 or 3" << endl;
- cin >> n;
- action = n;
- }
- };
- class Iguana : public Pet {
- public:
- int action;
- Iguana(string s, int n) :Pet(s) {
- action = n;
- };
- string Action() {
- if (action == 1) {
- string a = "Игуана бездействует \n";
- return a;
- }
- if (action == 2) {
- string a = "Игуана медитирует \n";
- return a;
- }
- }
- string Sound() override {
- return "Игуана " + this->name + " просто молчит\n";
- }
- void sast() {
- int n;
- cout << "1 or 2 " << endl; cin >> n;
- action = n;
- }
- };
- int main() {
- setlocale(LC_ALL, "ru");
- Homa Homa1("Хомяк", 1);
- //cout << Homa1.Action() << endl << endl;
- //Homa1.sast();
- //cout << Homa1.Action() << endl << endl;
- Popug Popug1("Попугай", 1);
- //cout << Popug1.Action() << endl << endl;
- //Popug1.sast();
- //cout << Popug1.Action() << endl << endl;
- Iguana Iguana1("Игуана", 1);
- //cout << Iguana1.Action() << endl << endl;
- //Iguana1.sast();
- //cout << Iguana1.Action() << endl;
- Pet** animals = new Pet*[3];
- animals[0] = &Homa1;
- animals[1] = &Popug1;
- animals[2] = &Iguana1;
- for (int i = 0; i < 3; i++) {
- cout << animals[i]->Sound() << endl;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement