-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path24_virtualbase.cpp
58 lines (57 loc) · 1.27 KB
/
24_virtualbase.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
#include<iostream>
using namespace std;
class Stdudent{
protected:
int id;
public:
void setid(int num){
id=num;
}
void printid(){
cout<<"Student Id is : "<<id<<endl;
}
};
class Marks: virtual public Stdudent {
protected:
float math , cpp;
public:
void setmarks(float m, float n){
math=m;
cpp =n ;
}
void printmarks(){
cout<<"Your marks in math is : "<<math<<endl;
cout<<"Your marks in C++ is : "<<cpp<<endl;
}
};
class Sports: virtual public Stdudent {
protected:
float score;
public:
void setscore(float s ){
score=s;
}
void printscore(){
cout<<"Your score in sports is : "<<score<<endl;
}
};
class Result:public Marks, public Sports{
float total;
public:
void display(){
total=score+math+cpp;
printid();
printmarks();
printscore();
cout<<"Total of all subjects are : "<<total<<endl;
}
};
int main ()
{
Result hardik;
hardik.setid(44); // Here is ambiguity resolved
hardik.setmarks(92.8 , 93.6);
hardik.setscore(97);
hardik.display();
return 0;
}