forked from NiharRanjan53/HacktoberFest_2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance
81 lines (66 loc) · 1.41 KB
/
inheritance
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
#include<iostream>
using namespace std;
class Vehicle{
protected:
string Make;
string Color;
int Year;
string Model;
public:
Vehicle(){
Make = "";
Color = "";
Year = 0;
Model = "";
}
Vehicle(string mk, string col, int yr, string mdl){
Make = mk;
Color = col;
Year = yr;
Model = mdl;
}
void print_details(){
cout << "Manufacturer: " << Make << endl;
cout << "Color: " << Color << endl;
cout << "Year: " << Year << endl;
cout << "Model: " << Model << endl;
}
};
class Cars: public Vehicle{
string trunk_size;
public:
Cars(){
trunk_size = "";
}
Cars(string mk, string col, int yr, string mdl, string ts)
:Vehicle(mk, col, yr, mdl){
trunk_size = ts;
}
void car_details(){
print_details();
cout << "Trunk size: " << trunk_size << endl;
}
};
class Ships: public Vehicle{
int Number_of_Anchors;
public:
Ships(){
Number_of_Anchors = 0;
}
Ships(string mk, string col, int yr, string mdl, int na)
:Vehicle(mk, col, yr, mdl){
Number_of_Anchors = na;
}
void Ship_details(){
print_details();
cout << "Number of Anchors: " << Number_of_Anchors << endl;
}
};
int main(){
Cars car("Chevrolet", "Black", 2010, "Camaro", "9.1 cubic feet");
car.car_details();
cout << endl;
Ships ship("Harland and Wolff, Belfast", "Black and whilte",
1912, "RMS Titanic", 3);
ship.Ship_details();
}