-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC++ Multi-level inheritance.cpp
75 lines (62 loc) · 1.15 KB
/
C++ Multi-level 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
//{ Driver Code Starts
//Initial Template for C++
#include <iostream>
using namespace std;
class student
{
protected :
int roll_number;
public:
void set_number(int a)
{
roll_number = a;
}
void display_number()
{
cout<<roll_number<<endl;
}
};
// } Driver Code Ends
//User function Template for C++
class test: public student
{
public:
float s1,s2,s3,s4,s5;
void set_marks(float *temp){
s1=temp[0];
s2=temp[1];
s3=temp[2];
s4=temp[3];
s5=temp[4];
}
};
class result: public test
{
public:
int hero=s1;
void display(){
float total=s1+s2+s3+s4+s5;
float average=total/5;
cout<<roll_number<<" "<<total<<" "<<average<<" "<<hero<<endl;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin>>t;
while(t--)
{
result student1;
int n;
cin>>n;
student1.set_number(n);
float temp[5];
int i;
for(i = 0; i < 5; i++)
cin>>temp[i];
student1.set_marks(temp);
student1.display();
}
return 0;
}
// } Driver Code Ends