SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void get_roll();
void put_roll();
};
void student::get_roll()
{
cout<<"\n Enter the Rollno:\t";
cin>>rollno;
}
void student::put_roll()
{
cout<<"\n The Rollno is:\t"<<rollno;
}
class subject:virtual public student
{
protected:
int sub1,sub2;
public:
void get_sub();
void put_sub();
};
void subject::get_sub()
{
cout<<"\n Enter the subject marks:\t";
cin>>sub1>>sub2;
}
void subject::put_sub()
{
cout<<"\n\n Marks scored in Subjects:\t";
cout<<sub1<<"\t"<<sub2<<"\n";
}
class sports:public virtual student
{
protected:
int spo;
public:
void get_spo();
void put_spo();
};
void sports::get_spo()
{
cout<<"\n Enter the sports marks:\t";
cin>>spo;
}
void sports::put_spo()
{
cout<<"\n Marks scored in Sports:\t"<<spo<<"\n";
}
class result:public subject,public sports
{
int res;
public:
void input();
void calculate();
void output();
};
void result::input()
{
get_roll();
get_sub();
get_spo();
}
void result::calculate()
{
res=sub1+sub2+spo;
}
void result::output()
{
put_roll();
put_sub();
put_spo();
cout<<"\n Total Result:\t"<<res;
}
void main()
{
result R;
clrscr();
R.input();
R.calculate();
R.output();
getch();
}
OUTPUT:
Enter the Rollno: 5072
Enter the subject marks: 80 80
Enter the sports marks: 75
The Rollno is: 5072
Marks scored in Subjects: 80 80
Marks scored in Sports: 75
Total Result: 235
EmoticonEmoticon