-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance_2.cpp
52 lines (44 loc) · 879 Bytes
/
Inheritance_2.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
#include <iostream>
using namespace std;
class Vehicle{
public:
string color;
int number;
int year;
void setData(string c, int n, int y){
color = c;
number = n;
year = y;
}
void getData(){
cout<<"Color: "<<color<<endl;
cout<<"Number: "<<number<<endl;
cout<<"Year: "<<year<<endl;
}
};
class Car: public Vehicle{
public:
string name;
void setName (string na){
name = na;
}
void getName(){
cout<<"Name: "<<name<<endl;
}
};
int main() {
Car myCar;
//Taking input
cout<<"Enter Color: ";
cin>>myCar.color;
cout<<"Enter Number: ";
cin>>myCar.number;
cout<<"Enter Year: ";
cin>>myCar.year;
cout<<"Enter name: ";
cin>>myCar.name;
//Displaying data
myCar.getData();
myCar.getName();
return 0;
}