File tree 1 file changed +87
-0
lines changed
1 file changed +87
-0
lines changed Original file line number Diff line number Diff line change
1
+ // write a programme to implement hierarchical inheritance
2
+ #include < iostream>
3
+ #include < string.h>
4
+ using namespace std ;
5
+ class person {
6
+ protected:
7
+ string name;
8
+ int age;
9
+ public:
10
+ void getpdata ();
11
+ void dispdata ();
12
+ };
13
+ void person::getpdata ()
14
+ {
15
+ getchar ();
16
+ cout<<" enter name" ;
17
+ getline (cin,name);
18
+ cout<<" enter age" ;
19
+ cin>>age;
20
+ }
21
+ void person::dispdata ()
22
+ {
23
+ cout<<" name" <<name<<endl;
24
+ cout<<" age is" <<age<<endl;
25
+ }
26
+ class employee :public person {
27
+ protected:
28
+ float salary;
29
+ string dept_name;
30
+ public:
31
+ void getedata ();
32
+ void dispedata ();
33
+ };
34
+ void employee::getedata ()
35
+ {
36
+ cout<<" enter salary" ;
37
+ cin>>salary;
38
+ cout<<" dept name" ;
39
+ getchar ();
40
+ getline (cin,dept_name);
41
+ }
42
+ void employee::dispedata ()
43
+ {
44
+ cout<<" name" <<name<<endl<<" salary" <<salary;
45
+ cout<<" dept" <<dept_name;
46
+ }
47
+ class student :public person {
48
+ protected:
49
+ int roll_no;
50
+ string grade;
51
+ public:
52
+ void getsdata ();
53
+ void dispsdata ();
54
+ };
55
+ void student::getsdata ()
56
+ {
57
+ cout<<" enter roll no" ;
58
+ cin>>roll_no;
59
+ cout<" grade" ;
60
+ getchar ();
61
+ getline (cin,grade);
62
+ }
63
+ void student::dispsdata ()
64
+ {
65
+ cout<<" name \t " <<name<<" roll no\t " <<roll_no<<" grade\t " <<grade;
66
+ }
67
+ int main ()
68
+ {
69
+ int c;
70
+ cout<<" 1.employee \t 2.student" ;
71
+ cin>>c;
72
+ if (c==1 )
73
+ {
74
+ employee e;
75
+ e.getpdata ();
76
+ e.getedata ();
77
+ e.dispedata ();
78
+ }
79
+ else
80
+ {
81
+ student s;
82
+ s.getpdata ();
83
+ s.getsdata ();
84
+ s.dispsdata ();
85
+ }
86
+ return 0 ;
87
+ }
You can’t perform that action at this time.
0 commit comments