-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop_ex5.c++
87 lines (73 loc) · 1.21 KB
/
oop_ex5.c++
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
//@rofi
#include<iostream>
using namespace std;
class Vehicle{
int engNum;
int regNum;
public:
Vehicle(){}
//setter
void setData()
{
cout<<"Input engine number:";
cin>>engNum;
cout<<"Input registration number:";
cin>>regNum;
}
//getter
void getData()
{
cout<<"engine number: "<<engNum<<endl;
cout<<"registration number: "<<regNum<<endl;
}
};
class Truck: public Vehicle
{
int capacity;
public:
Truck(){}
void setData()
{
cout<<"Input Truck details:";
Vehicle::setData();
cout<<"Input carrying capacity<in kgs>:";
cin>>capacity;
}
void getData()
{
Vehicle::getData();
cout<<"capacity:"<<capacity<<"kgs"<<endl;
}
};
class Bus: public Vehicle
{
int no_of_seats;
public:
Bus(){}
void setData()
{
cout<<"Input Bus details:";
Vehicle::setData();
cout<<"Input seat capacity:";
cin>>no_of_seats;
}
void getData()
{
Vehicle::getData();
cout<<"seat capacity:"<<no_of_seats<<endl;
}
};
int main()
{
cout<<"Truck instance creating:\n";
Truck truck1;
truck1.setData();
cout<<"***details of the truck***\n";
truck1.getData();
cout<<"Bus instance creating:\n";
Bus bus1;
bus1.setData();
cout<<"***details of the bus***\n";
bus1.getData();
return 0;
}