-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhierarchical_inheritance.cpp
87 lines (87 loc) · 1.39 KB
/
hierarchical_inheritance.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
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
//write a programme to implement hierarchical inheritance
#include<iostream>
#include<string.h>
using namespace std;
class person{
protected:
string name;
int age;
public:
void getpdata();
void dispdata();
};
void person::getpdata()
{
getchar();
cout<<"enter name";
getline(cin,name);
cout<<"enter age";
cin>>age;
}
void person::dispdata()
{
cout<<"name"<<name<<endl;
cout<<"age is"<<age<<endl;
}
class employee:public person{
protected:
float salary;
string dept_name;
public:
void getedata();
void dispedata();
};
void employee::getedata()
{
cout<<"enter salary";
cin>>salary;
cout<<"dept name";
getchar();
getline(cin,dept_name);
}
void employee::dispedata()
{
cout<<"name"<<name<<endl<<"salary"<<salary;
cout<<"dept"<<dept_name;
}
class student:public person{
protected:
int roll_no;
string grade;
public:
void getsdata();
void dispsdata();
};
void student::getsdata()
{
cout<<"enter roll no";
cin>>roll_no;
cout<"grade";
getchar();
getline(cin,grade);
}
void student::dispsdata()
{
cout<<"name \t"<<name<<"roll no\t"<<roll_no<<"grade\t"<<grade;
}
int main()
{
int c;
cout<<"1.employee \t 2.student";
cin>>c;
if(c==1)
{
employee e;
e.getpdata();
e.getedata();
e.dispedata();
}
else
{
student s;
s.getpdata();
s.getsdata();
s.dispsdata();
}
return 0;
}