-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance
54 lines (52 loc) · 1.07 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
// this code is an example of inheritance in C++
#include <iostream>
using namespace std;
class Employee
{
public:
float salary;
int vacationdays;
void getsalary()
{
// cout << "Employee's salary : "<<salary<<endl;
cout<<"No of vacation days: "<<vacationdays<<endl;
if( vacationdays == 0)
cout<<"Employee's salary : "<<salary * 1.1 <<endl;
else
cout << "Employee's salary : "<<salary<<endl;
}
};
class Manager: public Employee
{
public:
Manager(float s, int _vacationdays)
{
salary = s;
vacationdays = _vacationdays;
}
};
class Salesperson : public Employee
{
public:
Salesperson(float s, int _vacationdays)
{
salary = s;
vacationdays = _vacationdays;
}
};
class Engineer : public Employee
{
public:
Engineer(float s, int _vacationdays)
{
salary = s;
vacationdays = _vacationdays;
}
};
int main ()
{
Manager m1(250000, 3);
m1.getsalary();
Salesperson s1(250000,0);
s1.getsalary();
}