-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpa_lab_5_3_10_(3)-C.cpp
55 lines (45 loc) · 1.14 KB
/
cpa_lab_5_3_10_(3)-C.cpp
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
#include <iostream>
using namespace std;
class FarmAnimal
{
public:
FarmAnimal(double water_consumption);
double getWaterConsumption();
private:
double water_consumption;
};
FarmAnimal::FarmAnimal(double water_consumption)
{
this->water_consumption = water_consumption;
}
double FarmAnimal::getWaterConsumption()
{
return water_consumption;
}
class DummyAnimal : public FarmAnimal
{
public:
DummyAnimal();
};
DummyAnimal::DummyAnimal() : FarmAnimal(10.0){}
class DoublingAnimal : public FarmAnimal
{
public:
DoublingAnimal(double given_water_consumption);
};
DoublingAnimal::DoublingAnimal(double given_water_consumption) : FarmAnimal(2 * given_water_consumption) {}
void printConsumption(FarmAnimal animal)
{
cout << "This animal consumes " << animal.getWaterConsumption() << " liters of water" << endl;
}
int main()
{
FarmAnimal animalA(5);
DummyAnimal animalB;
DoublingAnimal animalC(21);
cout << "Animal consumes " << animalA.getWaterConsumption() << " liters of water." << endl;
cout << "What about the others ?" << endl;
printConsumption(animalB);
printConsumption(animalC);
return 0;
}