-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathanimal.cpp
More file actions
204 lines (149 loc) · 5.24 KB
/
animal.cpp
File metadata and controls
204 lines (149 loc) · 5.24 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class Animal
{
private:
int Age; //возраст в годах
float Weight; //вес в кг
public:
int getAge() const { return Age; }
void setAge(int ValueAge) { Age = ValueAge; }
float getWeight() const { return Weight; }
void setWeight(float ValueWeight) { Weight = ValueWeight; }
virtual string about() const { return (stringstream() << "Age = "<< Age <<", "<<"Weight = "<<Weight).str(); }
protected:
Animal() {};
Animal(int ValueAge, float ValueWeight)
{
setAge(ValueAge);
setWeight(ValueWeight);
}
};
class Mammal : public Animal
{
private:
int DurFeeding; //длительность вскармливания в неделях
string CoatColor; //цвет шерсти
public:
int getDurFeeding() const { return DurFeeding; }
void setDurFeeding(int ValueDurFeeding) { DurFeeding = ValueDurFeeding; }
string getCoatColor() const { return CoatColor; }
void setCoatColor(string Color) { CoatColor = Color; }
virtual string about() const { return (stringstream() << Animal::about() << ", " << "Duration of feeding = " << DurFeeding << ", " << "Coat color = " << CoatColor).str(); }
protected:
Mammal() {};
Mammal(int ValueAge, float ValueWeight, int ValueDurFeeding, string Color)
{
setAge(ValueAge);
setWeight(ValueWeight);
setDurFeeding(ValueDurFeeding);
setCoatColor(Color);
};
};
class Reptile : public Animal
{
private:
int NumEggs; //количество яиц в кладке
int DurMolting; //длительность линьки в днях, включая подготовку к ней
public:
int getNumEggs() const { return NumEggs; }
void setNumEggs(int ValueEggs) { NumEggs = ValueEggs; }
int getDurMolting() const { return DurMolting; }
void setDurMolting(int ValueMolting) { DurMolting = ValueMolting; }
virtual string about() const { return (stringstream() << Animal::about() << ", " << "Number of eggs = " << NumEggs << ", " << "Duration of molting = " << DurMolting).str(); }
protected:
Reptile() {};
Reptile(int ValueAge, float ValueWeight, int ValueEggs, int ValueMolting)
{
setAge(ValueAge);
setWeight(ValueWeight);
setNumEggs(ValueEggs);
setDurMolting(ValueMolting);
};
};
class Hedgehog : public Mammal
{
private:
int NumNeedles; //количество иголок
public:
int getNumNeedles() const { return NumNeedles; }
void setNumNeedles(int ValueNeedles) { NumNeedles = ValueNeedles; }
Hedgehog() {};
Hedgehog(int ValueAge, float ValueWeight, int ValueDurFeeding, string Color, int ValueNeedles)
{
setAge(ValueAge);
setWeight(ValueWeight);
setDurFeeding(ValueDurFeeding);
setCoatColor(Color);
setNumNeedles(ValueNeedles);
};
virtual string about() const { return (stringstream() << Mammal::about() << ", " << "Number of needles = " << NumNeedles).str(); }
};
class Giraffe : public Mammal
{
private:
float NeckLength; //длина шеи в метрах
public:
float getNeckLength() const { return NeckLength; }
void setNeckLength(float ValueLength) { NeckLength = ValueLength; }
Giraffe() {};
Giraffe(int ValueAge, float ValueWeight, int ValueDurFeeding, string Color, float ValueLength)
{
setAge(ValueAge);
setWeight(ValueWeight);
setDurFeeding(ValueDurFeeding);
setCoatColor(Color);
setNeckLength(ValueLength);
};
virtual string about() const { return (stringstream() << Mammal::about() << ", " << "Neck length = " << NeckLength).str(); }
};
class Cobra : public Reptile
{
private:
float Length; //длина в метрах
public:
float getLength() const { return Length; }
void setLength(float ValueLength) { Length = ValueLength; }
Cobra() {};
Cobra(int ValueAge, float ValueWeight, int ValueEggs, int ValueMolting, float ValueLength)
{
setAge(ValueAge);
setWeight(ValueWeight);
setNumEggs(ValueEggs);
setDurMolting(ValueMolting);
setLength(ValueLength);
};
virtual string about() const { return (stringstream() << Reptile::about() << ", " << "Length = " << Length).str(); }
};
class Crocodile : public Reptile
{
private:
int NumTeeth;
public:
int getNumTeeth() const { return NumTeeth; }
void setNumTeeth(int ValueTeeth) { NumTeeth = ValueTeeth; }
Crocodile() {};
Crocodile(int ValueAge, float ValueWeight, int ValueEggs, int ValueMolting, int ValueTeeth)
{
setAge(ValueAge);
setWeight(ValueWeight);
setNumEggs(ValueEggs);
setDurMolting(ValueMolting);
setNumTeeth(ValueTeeth);
};
virtual string about() const { return (stringstream() << Reptile::about() << ", " << "Number of teeth = " << NumTeeth).str(); }
};
int main()
{
Hedgehog a1(3, 0.8, 6, "gray", 4000);
cout << "Hedgehog: " << a1.about() << endl;
Giraffe a2(15, 700, 48, "yellow-brown", 1.9);
cout << "Giraffe: " << a2.about() << endl;
Cobra a3(17, 6, 20, 10, 3);
cout << "Cobra: " << a3.about() << endl;
Crocodile a4(55, 400, 10, 5, 67);
cout << "Crocodile : " << a4.about() << endl;
return 0;
}