-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.cpp
More file actions
70 lines (62 loc) · 1.04 KB
/
Copy pathInheritance.cpp
File metadata and controls
70 lines (62 loc) · 1.04 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
//Inheritance
#include <iostream>
#include <string.h>
using namespace std;
class Person
{
private: //accessible only in this class
int age;
char name[20];
protected: //not accessible with object of this class
void setName(char *n)
{
strcpy(name,n);
}
void setAge(int a)
{
age = a;
}
public:
char* getName()
{
return(name);
}
int getAge()
{
return age;
}
};
//inheritance of class Person
class Employee:public Person
{
private:
float sallary;
protected:
void setSallary(float s)
{
sallary = s;
}
float getSallary()
{
return sallary;
}
public:
void setEmployee(char *N,int A,float S)
{
setName(N);
setAge(A);
setSallary(S);
}
void showEmployee()
{
cout<<" Name is "<<getName()<<" Sallary is "<<getSallary()<<" Age is "<<getAge()<<endl;
}
};
int main()
{
system("cls");
Employee emp;
emp.setEmployee("Ruby",20,30000);
emp.showEmployee();
system("pause");
}