-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.cpp
More file actions
111 lines (88 loc) · 1.96 KB
/
Animal.cpp
File metadata and controls
111 lines (88 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <string>
using namespace std;
class Animal
{
protected:
string name;
public:
Animal(string animalName) {
name = animalName;
}
virtual void makeNoise() {
cout << "Æèâîòíîå èçäàåò çâóê" << endl;
}
virtual void eat() {
cout << "Æèâîòíîå ïèòàåòñÿ" << endl;
}
virtual string getDescription() {
return "Ýòî æèâîòíîå";
}
string getName() {
return name;
}
};
class Dog : public Animal
{
public:
Dog(string dogName) : Animal(dogName) {}
void makeNoise() override {
cout << "Ñîáàêà ãàâêàåò" << endl;
}
void eat() override {
cout << "Ñîáàêà åñò êîñòü" << endl;
}
string getDescription() override {
return "Ýòî ñîáàêà";
}
};
class Cat : public Animal
{
public:
Cat(string catName) : Animal(catName) {}
void makeNoise() override {
cout << "Êîøêà ìÿóêàåò" << endl;
}
void eat() override {
cout << "Êîøêà åñò ðûáó" << endl;
}
string getDescription() override {
return "Ýòî êîøêà";
}
};
class Bear : public Animal
{
public:
Bear(string bearName) : Animal(bearName) {}
void makeNoise() override {
cout << "Ìåäâåäü ðû÷èò" << endl;
}
void eat() override {
cout << "Ìåäâåäü åñò ì¸ä" << endl;
}
string getDescription() override {
return "Ýòî ìåäâåäü";
}
};
class Vet
{
public:
void treatAnimal(Animal* animal) {
cout << "Âåòåðèíàð îáñëóæèâàåò: " << animal->getName() << ". " << animal->getDescription() << endl;
}
};
int main()
{
setlocale(LC_ALL, "RUS");
Animal* animals[3] = {
new Dog("Øàðèê"),
new Cat("Ìóðêà"),
new Bear("Ìèøà")
};
Vet vet;
for (int i = 0; i < 3; ++i) {
vet.treatAnimal(animals[i]);
delete animals[i];
}
return 0;
}