-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathmammal.h
More file actions
66 lines (56 loc) · 2.04 KB
/
Copy pathmammal.h
File metadata and controls
66 lines (56 loc) · 2.04 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
#pragma once
#include <iostream>
#include "animal.h"
class Mammal : public Animal {
private:
float pregnancyDuration; // days
public:
const float getPregnancyDuration() const { return pregnancyDuration; }
void setPregnancyDuration(const float d) { pregnancyDuration = d; }
protected:
Mammal(const float pd, const float weight) : Animal(weight) {
pregnancyDuration = pd;
}
};
class Cat : public Mammal {
private:
float vibrissaLength; // meters
public:
Cat(const float vl, const float pd, const float weight) : Mammal(pd, weight) {
vibrissaLength = vl;
}
const float getVibrissaLength() const { return vibrissaLength; }
void setVibrissaLength(const float v) { vibrissaLength = v; }
};
enum Breed { Sharpey, Terier, Chauchau };
class Dog : public Mammal {
private:
Breed breed;
public:
Dog(const Breed b, const float pd, const float weight) : Mammal(pd, weight) {
breed = b;
}
const Breed getBreed() const { return breed; }
void setBreed(const Breed b) { breed = b; }
const std::string getBreedAsString() const {
std::string strBreed = "";
switch (breed) {
case Sharpey: strBreed = "sharpey"; break;
case Terier: strBreed = "terier"; break;
case Chauchau: strBreed = "chau chau"; break;
}
return strBreed;
}
};
std::ostream& operator << (std::ostream& os, const Cat& c) {
os << "cat's vibrissa length: " << c.getVibrissaLength() << std::endl;
os << "cat's pregnancy duration: " << c.getPregnancyDuration() << std::endl;
os << "cat's weight: " << c.getWeight() << std::endl;
return os;
}
std::ostream& operator << (std::ostream& os, const Dog& d) {
os << "dog's breed: " << d.getBreedAsString() << std::endl;
os << "dog's pregnancy duration: " << d.getPregnancyDuration() << std::endl;
os << "dog's weight: " << d.getWeight() << std::endl;
return os;
}