-
Notifications
You must be signed in to change notification settings - Fork 0
/
47-POO-Classes-Inheritance.h
95 lines (81 loc) · 1.7 KB
/
47-POO-Classes-Inheritance.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
90
91
92
93
94
95
#ifndef 47-POO-CLASSES-INHERITANCE_H_INCLUDED
#define 47-POO-CLASSES-INHERITANCE_H_INCLUDED
class Vehicle(){
public:
int spd;
int bulPoof;
int wheels;
void setType(int tp);
void setTopSpd(int ts);
void setWeapon(bool wp);
private:
int type; // 1 = Moto 2 = Car 3 = Truck 4 = Tank
int topSpd;
bool weapon;
};
void Vehicle()::disp(){
std::cout << "Vehicle Type .......: " << type << std::endl;
std::cout << "Top Speed ..........: " << topSpd << std::endl;
std::cout << "Number of Wheels ...: " << wheels << std::endl;
std::cout << "Bulletproof ........: " << bulProof << std::endl;
std::cout << "Weapons? ...........: " << weapon << std::endl;
std::cout << "................................................ " << std::endl;
}
void Vehicle::setType(int tp){
type = tp;
}
void Vehicle::setTopSpd(int ts){
topSpd = ts;
}
void Vehicle::setWeapon(bool wp){
weapon = wp;
}
class Moto:public Vehicle(){
public:
Moto();
};
Moto::Moto(){
spd=0;
blind=0;
wheels=2;
setType(1);
setTopSpd(120);
setWeapon(false);
}
class Car:public Vehicle(){
public:
Car();
};
Car::Car(){
spd=0;
blind=0;
wheels=4;
setType(2);
setTopSpd(180);
setWeapon(false);
}
class Truck:public Vehicle(){
public:
Truck();
};
Truck::Truck(){
spd=0;
blind=0;
wheels=6;
setType(3);
setTopSpd(180);
setWeapon(false);
}
class Tank:public Vehicle(){
public:
Tank();
};
Tank::Tank(){
spd=0;
blind=1;
wheels=8;
setType(4);
setTopSpd(80);
setWeapon(true);
}
#endif // 47-POO-CLASSES-INHERITANCE_H_INCLUDED