-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathanimal.cpp
More file actions
105 lines (86 loc) · 2.84 KB
/
Copy pathanimal.cpp
File metadata and controls
105 lines (86 loc) · 2.84 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
#include "animal.h"
using namespace std;
Animal::Animal(float _weight, int _age) {
weight = _weight;
age = _age;
}
string Animal::about() const {
stringstream ss;
ss << "Weight: " << weight << " kg" << ", age: " << age << " years";
return ss.str();
}
ostream& operator << (ostream &out, const Animal &animal) {
return out << animal.about();
}
Mammal::Mammal(float _weight, int _age, int _pregnancyLength) : Animal(_weight, _age) {
pregnancyLength = _pregnancyLength;
}
string Mammal::about() const {
stringstream ss;
ss << Animal::about();
ss << ", pregnancyLength: " << pregnancyLength << " days";
return ss.str();
}
Reptile::Reptile(float _weight, int _age, float _eggHeight) : Animal(_weight, _age) {
eggHeight = _eggHeight;
}
string Reptile::about() const {
stringstream ss;
ss << Animal::about();
ss << ", eggHeight: " << eggHeight << " centimeters";
return ss.str();
}
Cat::Cat(float _weight, int _age, int _pregnancyLength, float _vibrissaeLength) : Mammal(_weight, _age, _pregnancyLength) {
vibrissaeLength = _vibrissaeLength;
}
string Cat::about() const {
stringstream ss;
ss << Mammal::about();
ss << ", vibrissaeLength: " << vibrissaeLength << " centimeters";
return ss.str();
}
Dog::Dog(float _weight, int _age, int _pregnancyLength, string _breed) : Mammal(_weight, _age, _pregnancyLength) {
breed = move(_breed);
}
string Dog::about() const {
stringstream ss;
ss << Mammal::about();
ss << ", breed: " << breed;
return ss.str();
}
Turtle::Turtle(float _weight, int _age, float _eggHeight, float _shellSize) : Reptile(_weight, 4, _eggHeight) {
shellSize = _shellSize;
}
string Turtle::about() const {
stringstream ss;
ss << Reptile::about();
ss << ", shellSize: " << shellSize << " meters";
return ss.str();
}
Snake::Snake(float _weight, int _age, float _eggHeight, float _length) : Reptile(_weight, _age, _eggHeight) {
length = _length;
}
string Snake::about() const {
stringstream ss;
ss << Reptile::about();
ss << ", length: " << length << " meters";
return ss.str();
}
int main()
{
// tests:
Dog dog_1 = Dog(25, 4, 60, "Husky");
Cat cat_1 = Cat(10, 8, 65, 7);
Turtle turtle_1 = Turtle(100, 2, 8, 2.35);
Snake python = Snake(50, 12, 0.38, 5);
cout << "dog_1: " << dog_1.about() << endl;
cout << "cat_1: " << cat_1.about() << endl;
cout << "turtle_1: " << turtle_1.about() << endl;
cout << "python: " << python.about() << endl;
cout << "" << endl;
cout << "dog_1: " << dog_1 << endl;
cout << "cat_1: " << cat_1 << endl;
cout << "turtle_1: " << turtle_1 << endl;
cout << "python: " << python << endl;
return 0;
}