-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathanimal.h
More file actions
98 lines (86 loc) · 2.65 KB
/
animal.h
File metadata and controls
98 lines (86 loc) · 2.65 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
#pragma once
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class Animal
{
public:
float getWeight() const { return weight; }
void setWeight(float weight) { this->weight = weight; }
virtual std::string about() const { return (std::stringstream() << "weight =" << weight).str(); }
private:
float weight;
protected:
Animal() //êàê êîíñòðóêòîð ïî óìîë÷àíèþ
{
weight = 0.;
}
Animal(float weight)
{
this->weight = weight;
}
};
class Mammal : public Animal
{
private:
int pregnancyDuration;
public:
int getPregnancyDuration() const { return pregnancyDuration; }
void setpregnancyDuration(int period) { pregnancyDuration = period; }
virtual std::string about() const { return (std::stringstream() << Animal::about() << ", " << "pregnancyDuration =" << pregnancyDuration).str(); }
protected:
Mammal() {
pregnancyDuration = 0;
}
Mammal(float weight, int period) :Animal(weight) { pregnancyDuration = period; }
};
class Cat : public Mammal
{
private:
float vibrissaLength;
public:
float getVibrissaLength() const { return vibrissaLength; }
void setvibrissaLength(int length) { vibrissaLength = length; }
Cat(float weight, int period, float length) :Mammal(weight, period) { vibrissaLength = length; }
virtual std::string about() const { return (std::stringstream() << Animal::about() << ", " << Mammal::about() << ", " << "vibrasaLength =" << vibrissaLength).str(); }
Cat() {
vibrissaLength = 0;
}
};
class Giraffe : public Mammal
{
private:
int height;
public:
int getHeight() const { return height; }
void setHeight(int height) { this->height = height; }
Giraffe(float weight, int period, int height) :Mammal(weight, period) { setHeight(height); }
virtual std::string about() const { return (std::stringstream() << Animal::about() << ", " << Mammal::about() << ", " << "heigth = " << height).str(); }
Giraffe() { height = 0; }
};
class Fish : public Animal
{
private:
int size;
public:
int getSize() const { return size; }
void setSize(int size) { this->size = size; }
virtual std::string about() const { return (std::stringstream() << Animal::about() << ", " << "size =" << size).str(); }
protected:
Fish(float weight, int size) :Animal(weight) { setSize(size); }
Fish() {
size = 0;
}
};
class Shark : public Fish
{
private:
int jawSize;// ðàçìåð ÷åëþñòè
public:
int getJawSize() const { return jawSize; }
void setJawSize(int size) { jawSize = size; }
Shark(float weight, int size, int jawSize) :Fish(weight, size) {setJawSize(jawSize);}
Shark() { jawSize = 0; }
virtual std::string about() const { return (std::stringstream() << Animal::about() << ", " << Fish::about() << ", " << "jawSize =" << jawSize).str();}
};