Create a base class Student(Roll No, Name) which derives two classes Test (Mark1, Mark2)
and Sport(Score). Result(total marks, grade) class inherits both Test and Sport classes.
Write a C++ menu driven program to perform the following functions:
•Build a master table• Calculate total of marks and grade •Display the details of all students in ascending order of marks.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class student{
protected:
int rno;
char name[10];
public:
void getdata()
{
cout<<"Enter Student’s Data:\n\tRoll No.: ";
cin>>rno;
cout<<"\tName: ";
gets(name);
fflush(stdin);
}
};
class test:public virtual student{
protected:
float mk1,mk2;
public:
void get_t_data(){
cout<<"\tMarks:\n\t\tSubject 1: ";
cin>>mk1;
cout<"\t\tSubject2: ";
cin>>mk2;
}
};
class sport:public virtual student{
protected:
float score;
public:
void get_s_data(){
cout<<"\t\tSports: ";
cin>>score;
}
};
class result:public test, public sport{
char grade;
public:
int tot_mks;
void cal(){
tot_mks=mk1+mk2+score;
if((tot_mks/3)>60)
grade='A';
else if((tot_mks/3)>50)
grade='B';
else if((tot_mks/3)>40)
grade='C';
else
grade='F';
}
void display(){
cout<<"\n"<<rno<<"\t "<<name;
cout<<"\t "<<mk1<<"\t "<<mk2<<"\t "<<score;
cout<<"\t"<<tot_mks<<"\t "<<grade;
}
};
void main()
{
clrscr();
result r[20];
int n, n1=0, ch, i=0, j;
cout<<"\n\n\t1.Build Master Table.
\n\t2.Calculate Total Marks And Grade.
\n\t3.Display Details in Ascending order of marks.
\n\t4.EXIT.";
while(1)
{
cout<<"\n\nEnter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the number of students: ";
cin>>n;
n1=n+n1;
for(;i<n1;++i){
r[i].getdata();
r[i].get_t_data();
r[i].get_s_data();
}
cout<<"\n\nMaster Table Built Successfully.";
break;
case 2: for(j=0;j<n1;++j)
r[j].cal();
cout<<"\n\nCalculation Done.";
break;
case 3:
cout<<"\n\nRNO\t Name\t Sub1\t Sub2\t Score\t Total(Average)
\t Grade";
int str[15],tmp;
for(int i=0;i<n1;i++)
str[i]=r[i].tot_mks;
for(i=0;i<n1;i++)
for(int j=i+1;j<n1;j++){
if(str[i]>str[j]){
tmp=str[i];
str[i]=str[j];
str[j]=tmp;
}
}
for(i=0;i<n1;i++)
for(j=0;j<n1;j++){
if(str[i]==r[j].tot_mks){
r[j].display();
break;
}
}
break;
case 4: goto end;
}
}
end:
}
and Sport(Score). Result(total marks, grade) class inherits both Test and Sport classes.
Write a C++ menu driven program to perform the following functions:
•Build a master table• Calculate total of marks and grade •Display the details of all students in ascending order of marks.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class student{
protected:
int rno;
char name[10];
public:
void getdata()
{
cout<<"Enter Student’s Data:\n\tRoll No.: ";
cin>>rno;
cout<<"\tName: ";
gets(name);
fflush(stdin);
}
};
class test:public virtual student{
protected:
float mk1,mk2;
public:
void get_t_data(){
cout<<"\tMarks:\n\t\tSubject 1: ";
cin>>mk1;
cout<"\t\tSubject2: ";
cin>>mk2;
}
};
class sport:public virtual student{
protected:
float score;
public:
void get_s_data(){
cout<<"\t\tSports: ";
cin>>score;
}
};
class result:public test, public sport{
char grade;
public:
int tot_mks;
void cal(){
tot_mks=mk1+mk2+score;
if((tot_mks/3)>60)
grade='A';
else if((tot_mks/3)>50)
grade='B';
else if((tot_mks/3)>40)
grade='C';
else
grade='F';
}
void display(){
cout<<"\n"<<rno<<"\t "<<name;
cout<<"\t "<<mk1<<"\t "<<mk2<<"\t "<<score;
cout<<"\t"<<tot_mks<<"\t "<<grade;
}
};
void main()
{
clrscr();
result r[20];
int n, n1=0, ch, i=0, j;
cout<<"\n\n\t1.Build Master Table.
\n\t2.Calculate Total Marks And Grade.
\n\t3.Display Details in Ascending order of marks.
\n\t4.EXIT.";
while(1)
{
cout<<"\n\nEnter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the number of students: ";
cin>>n;
n1=n+n1;
for(;i<n1;++i){
r[i].getdata();
r[i].get_t_data();
r[i].get_s_data();
}
cout<<"\n\nMaster Table Built Successfully.";
break;
case 2: for(j=0;j<n1;++j)
r[j].cal();
cout<<"\n\nCalculation Done.";
break;
case 3:
cout<<"\n\nRNO\t Name\t Sub1\t Sub2\t Score\t Total(Average)
\t Grade";
int str[15],tmp;
for(int i=0;i<n1;i++)
str[i]=r[i].tot_mks;
for(i=0;i<n1;i++)
for(int j=i+1;j<n1;j++){
if(str[i]>str[j]){
tmp=str[i];
str[i]=str[j];
str[j]=tmp;
}
}
for(i=0;i<n1;i++)
for(j=0;j<n1;j++){
if(str[i]==r[j].tot_mks){
r[j].display();
break;
}
}
break;
case 4: goto end;
}
}
end:
}