-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualBaseClass.cpp
86 lines (73 loc) · 1.34 KB
/
VirtualBaseClass.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
#include <iostream>
using namespace std;
// Student ---> Test [Done]
// Student ---> Sports [Done]
// Test ---> Result
// Sports ---> Result
class Student
{
protected:
int roll_no;
public:
void get_roll_no(int r)
{
roll_no = r;
}
void set_roll_no()
{
cout << "Roll No: " << roll_no << endl;
}
};
class Test : virtual public Student
{
protected:
float maths_marks, physics_marks;
public:
void get_marks(float m, float p)
{
maths_marks = m;
physics_marks = p;
}
void set_marks()
{
cout << "maths: " << maths_marks << endl;
cout << "physics: " << physics_marks << endl;
}
};
class Sports : virtual public Student
{
protected:
int score;
public:
void get_score(int s)
{
score = s;
}
void set_score()
{
cout << "The score is: " << score << endl;
}
};
class Result : public Test, public Sports
{
private:
float total;
public:
void display_total()
{
total = maths_marks + physics_marks + score;
set_roll_no();
set_score();
set_marks();
cout << "Your total score is: " << total << endl;
}
};
int main()
{
Result Daniyal;
Daniyal.get_roll_no(6880);
Daniyal.get_marks(89.3, 38.0);
Daniyal.get_score(99);
Daniyal.display_total();
return 0;
}