forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.cpp
More file actions
105 lines (90 loc) · 1.94 KB
/
inheritance.cpp
File metadata and controls
105 lines (90 loc) · 1.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<iostream>
using namespace std;
//Base class
class Employee
{
private:
int salary;
public:
int empId;
Employee(int inpId)
{
empId = inpId;
}
Employee(){}
void showData(void)
{
cout<<"The id of Employee is"<<empId<<endl;
}
};
//Derived Class Coder
class Coder : public Employee{
public:
int langCode;
int langStar;
Coder(int _langCode , int id)
{
langCode = _langCode;
langStar = 12;
empId = id ;
}
void getCoder(void)
{
cout<<"The language code and the language start od the coder is "<<langStar<<" "<<langCode<<" "<<empId<<endl;
}
};
// **********************ANOTHER EXAMPLE FOR INHERITANCE ***********************
//BASE CLASS
class Vechile{
private:
int heatRate=788;
public:
int milage;
string model ;
Vechile(int mil , string mod)
{
milage = mil;
model = mod;
}
void getData(void)
{
cout<<"The milage is: "<<milage<<endl;
cout<<"The model is :"<<model<<endl;
}
Vechile(){} //default constructor
;};
//DERIVED CLASS
class Car : public Vechile{
public:
int xrfSpeed ;
Car(int xrf)
{
xrfSpeed =xrf;
}
Car(int mil , string mod)
{
milage =mil;
model =mod;
}
void speed(void)
{
cout<<"The speed of the car is "<<xrfSpeed<<endl;
}
Car();
};
int main()
{
Employee rohan(200) , tan(56);
rohan.showData();
tan.showData();
Coder ram(3,45), python(5,56);
ram.getCoder();
python.getCoder();
ram.showData();
//********OBJECTS OF CLASS VECHILES AND ITS DERIVED CLSSS************
Vechile lamborghini(23,"lamborghini vX1");
lamborghini.getData();
Car alto(343, "alto800");
alto.getData();
return 0;
}