-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultilevel_inheritance.cpp
99 lines (99 loc) · 1.58 KB
/
multilevel_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
88
89
90
91
92
93
94
95
96
97
98
99
//write a programme to implement multilevel inheritance
#include<iostream>
#include<string.h>
using namespace std;
class student{
protected:
string name;
int roll_no;
public:
void getsdata();
void dispdata();
};
void student::getsdata()
{
getchar();
cout<<"enter your name";
getline(cin,name);
cout<<"enter roll no";
cin>>roll_no;
}
void student::dispdata()
{
cout<<"name"<<name<<"\n roll no"<<roll_no;
}
class test:public student{
protected:
float mark[5];
public:
void gettdata();
void disptdata();
};
void test::gettdata(){
for(int i=0;i<5;i++)
{
cout<<"enter mark of subject"<<i+1;
cin>>mark[i];
}
}
void test::disptdata(){
cout<<"name "<<name<<"\n roll no"<<roll_no<<"\n marks";
for(int i=0;i<5;i++)
{
cout<<"\t mark of subject"<<i+1;
cout<<mark[i]<<endl;
}
}
class result:public test{
protected:
float r;
public:
result()
{
r=0;
}
void calculate();
void disprdata();
};
void result::calculate(){
for(int i=0;i<5;i++){
r+=mark[i];
r/=5;
}
}
void result::disprdata(){
cout<<"name"<<name<<"\n roll no"<<roll_no<<"\n marks";
for(int i=0;i<5;i++)
{
cout<<"\t mark of subject"<<i+1;
cout<<mark[i]<<endl;
}
cout<<"result"<<r<<endl;
}
int main(){
int c;
cout<<"1.student \n 2.test \n 3.result";
cin>>c;
if(c==1)
{
student s;
s.getsdata();
s.dispdata();
}
else if(c==2)
{
test t;
t.getsdata();
t.gettdata();
t.disptdata();
}
else
{
result r;
r.getsdata();
r.gettdata();
r.calculate();
r.disprdata();
}
return 0;
}