-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq50.cpp
84 lines (68 loc) · 1.52 KB
/
q50.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
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
/*
* WAP to demonstrate pure virtual function
* Create three classes Vehicle, Car and Bus in such a way that Bus and Car
* are derived from the Vehicle class. Write the class implementation where
* Vehicle will have only pure virtual function.
*/
#include <iostream>
using namespace std;
class Vehicle {
public:
virtual void start_engine() = 0;
virtual void stop_engine() = 0;
virtual void drive() = 0;
virtual void stop_driving() = 0;
};
class Car : public Vehicle {
public:
void start_engine();
void stop_engine();
void drive();
void stop_driving();
};
void Car::start_engine() {
cout << "Car engine started!\n";
}
void Car::stop_engine() {
cout << "Car engine stopped.\n";
}
void Car::drive() {
cout << "Driving car.\n";
}
void Car::stop_driving() {
cout << "Stopped driving car.\n";
}
class Bus : public Vehicle {
public:
void start_engine();
void stop_engine();
void drive();
void stop_driving();
};
void Bus::start_engine() {
cout << "Bus engine started!\n";
}
void Bus::stop_engine() {
cout << "Bus engine stopped.\n";
}
void Bus::drive() {
cout << "Driving bus.\n";
}
void Bus::stop_driving() {
cout << "Stopped driving bus.\n";
}
int main() {
Car c;
Bus b;
cout << "CAR:\n";
c.start_engine();
c.drive();
c.stop_driving();
c.stop_engine();
cout << "BUS:\n";
b.start_engine();
b.drive();
b.stop_driving();
b.stop_engine();
return 0;
}