-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleinheritance3.cpp
More file actions
72 lines (64 loc) · 1.51 KB
/
singleinheritance3.cpp
File metadata and controls
72 lines (64 loc) · 1.51 KB
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
//Variation 3
#include<iostream>
using namespace std;
class car //base class
{
protected: //Access Specifier
int color;
char fuel;
public:
void input()
{
cout << "Enter color of your car :" << endl;
cout << "1. Silver \n2. Golden \n3. Black" << endl;
cin >> color;
cout << "Enter fuel type of your car : \n";
cin >> fuel;
}
/*void showdata()
{
if(color==1)
cout << "Color of your car is Silver" << endl;
else if(color==2)
cout << "Color of your car is Golden" << endl;
else if(color==3)
cout << "Color of your car is Black" << endl;
else
cout << "This Color Code doesn't exist" << endl;
cout << "Fuel of your car is " << fuel;
}*/
};
class sportscar:public car
{
private:
int maxspeed;
int alarm;
int airbags;
public:
void getdata()
{
cout << "Enter Maximum Speed of your car :" << endl;
cin >> maxspeed;
cout << "Enter number of Alarms in your car : " << endl;
cin >> alarm;
cout << "Enter number of Air Bags in your car : " << endl;
cin >> airbags;
}
void setdata()
{
cout << "Maximum Speed of your car : " << maxspeed << endl;
cout << "Alarms in your car : " << alarm << endl;
cout << "Air Bags in your car : " << airbags << endl;
cout << "Color of Car : " << color << endl;
cout << "Fuel of car : " << fuel << endl;
}
};
int main()
{
sportscar tesla;
tesla.input();
// tesla.showdata();
tesla.getdata();
tesla.setdata();
return 0;
}