-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path26_Vehicle.cpp
60 lines (51 loc) · 1.13 KB
/
26_Vehicle.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
/*
Program: 26
Write a program in C++ to declare a class of Vehicle. Derived classes are two-wheelers,
three wheelers. Display the properties of each type of vehicle using the member functions of class.
*/
#include <iostream>
using namespace std;
class Vehicle
{
public:
void displayProperties()
{
cout << "Vehicle type: Generic" << endl;
}
};
class TwoWheeler : public Vehicle
{
public:
void displayProperties()
{
cout << "Vehicle type: Two-Wheeler" << endl;
cout << "Number of wheels: 2" << endl;
}
};
class ThreeWheeler : public Vehicle
{
public:
void displayProperties()
{
cout << "Vehicle type: Three-Wheeler" << endl;
cout << "Number of wheels: 3" << endl;
}
};
int main()
{
Vehicle vehicle;
vehicle.displayProperties();
TwoWheeler twoWheeler;
twoWheeler.displayProperties();
ThreeWheeler threeWheeler;
threeWheeler.displayProperties();
return 0;
}
/*
Output:
Vehicle type: Generic
Vehicle type: Two-Wheeler
Number of wheels: 2
Vehicle type: Three-Wheeler
Number of wheels: 3
*/