-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro6.h
89 lines (78 loc) · 1.98 KB
/
pro6.h
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
#include <iostream>
using namespace std;
class vehicle{
private:
int wheels;
double weight;
public:
vehicle(int wheels, double weight) {
this->wheels = wheels;
this->weight = weight;
}
int getWheels() const {
return wheels;
}
void setWheels(int wheels) {
vehicle::wheels = wheels;
}
double getWeight() const {
return weight;
}
void setWeight(double weight) {
vehicle::weight = weight;
}
};
class car: private vehicle{
private:
int passenger_load;
public:
car(int wheels, double weight, int passenger_load):vehicle(wheels, weight){
this->passenger_load = passenger_load;
}
int getPassengerLoad() const {
return passenger_load;
}
void setPassengerLoad(int passengerLoad) {
passenger_load = passengerLoad;
}
void outInfo(){
cout << "weight=" << this->getWeight() <<" wheels=" << this->getWheels() << " passenger_load=" <<this->getPassengerLoad();
}
};
class truck: private vehicle{
private:
int passenger_load;
double payload;
public:
truck(int wheels, double weight, int passenger_load, double payload):vehicle(wheels, weight){
this->passenger_load = passenger_load;
this->payload = payload;
}
int getPassengerLoad() const {
return passenger_load;
}
void setPassengerLoad(int passengerLoad) {
passenger_load = passengerLoad;
}
double getPayload() const {
return payload;
}
void setPayload(double payload) {
truck::payload = payload;
}
void outInfo(){
cout << "weight=" << this->getWeight() <<" wheels=" << this->getWheels()
<< " passenger_load=" <<this->getPassengerLoad()
<< " payload=" << this->getPayload();
}
};
int main(){
vehicle v(2, 5.0);
cout << v.getWheels() << "\t" << v.getWeight();
car c( 4, 2, 5);
c.outInfo();
cout << endl;
truck t(8,8,2,10);
t.outInfo();
return 0;
}