Friday, 22 June 2012

write a c++ program to create a base class student (roolno,name) which derived two classes test(marks1,marks2) and sports(score), result(total marks,grade) class inherits both test and sports classes write a c++ menu driven program to perform the following

/*
write a c++ program to create a base class student (roolno,name) which derived
two classes test(marks1,marks2) and sports(score),
result(total marks,grade) class inherits both test and sports
classes write a c++ menu driven program to perform the following
function
-build a master table
-calculate total of marks and grade
-display the details of all student in ascending order of marks.
*/
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
int i,n,sc[10];
int j,temp=0;
char t[20];
class student
{
public:int rno;
       char name[20];
     };
class result
{
public:int tot;
       char grade;
       };
class test:public student,public result
{
public:int m1,m2;
public:void t_accept()
       {
       cout<<"\nenter rollno:-";
       cin>>rno;
       cout<<"\nenter name:-";
       cin>>name;
       cout<<"\nenter marks1:-";
       cin>>m1;
       cout<<"\nenter marks2:-";
       cin>>m2;
       }
       void calc()
       {
       tot=m1+m2;
       if(tot>=75)
       grade='A';
       else
       if(tot>=60&&tot<75)
       grade='B';
       else
       if(tot>=40&&tot<60)
       grade='c';
       else
       grade='f';
       }
       void sort1();
}r[20];
void test::sort1()
{
       for(i=0;i<n;i++)
       {
       for(j=i+1;j<n;j++)
       {
       if(r[i].tot>r[j].tot)
       {
       temp=r[i].tot;
       r[i].tot=r[j].tot;
       r[j].tot=temp;
       temp=r[i].grade;
       r[i].grade=r[j].grade;
       r[j].grade=temp;
       temp=r[i].m1;
       r[i].m1=r[j].m1;
       r[j].m1=temp;
       temp=r[i].m2;
       r[i].m2=r[j].m2;
       r[j].m2=temp;
       temp=r[i].rno;
       r[i].rno=r[j].rno;
       r[j].rno=temp;
       strcpy(t,r[i].name);
       strcpy(r[i].name,r[j].name);
       strcpy(r[j].name,t);
       }
       }
       }
       cout<<"\nrno"<<"\tname"<<"\tmarks1"<<"\tmarks2"<<"\ttotalmarks"
       <<"  grade"<<"\tscore\n";
       for(i=0;i<n;i++)
       cout<<"\n"<<r[i].rno<<"\t"<<r[i].name<<"\t"<<r[i].m1<<"\t"<<r[i].m2
       <<"\t"<<r[i].tot<<"\t\t"<<r[i].grade<<"\t\t"<<sc[i];

}
class sports:public student,public result
{
public:int score;
public:void s_accept()
       {
       cout<<"\nenter the score:-";
       cin>>score;
       }
       void sort2();

}s[20];
void sports::sort2()
{
       for(i=0;i<n;i++)
       {
       for(j=i+1;j<n;j++)
       {
       if(r[i].tot>r[j].tot)
       {
       temp=s[i].score;
       s[i].score=s[j].score;
       s[j].score=temp;
       }
       }
       }
       for(i=0;i<n;i++)
       sc[i]=s[i].score;
}
int main()
{
int ch;
char t[20];
clrscr();
cout<<"\nenter how many records is to be store:-";
cin>>n;
while(1)
{
cout<<"\n1:built a master table";
cout<<"\n2:calculate total of marks and grade";
cout<<"\n3:display the details of all ascending oeder of marks";
cout<<"\n4:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:for(i=0;i<n;i++)
       {
       r[i].t_accept();
       s[i].s_accept();
       }
       break;
case 2:for(i=0;i<n;i++)
       r[i].calc();
       break;
case 3:test t;
       sports s;
       s.sort2();
       t.sort1();
       break;
case 4:exit(0);
}
}
getch();
return 0;
}
/*
enter how many records is to be store:-2
                                                                               
1:built a master table                                                         
2:calculate total of marks and grade                                           
3:display the details of all ascending oeder of marks                          
4:exit                                                                         
enter your choice:-1                                                           
                                                                               
enter rollno:-1                                                                
                                                                               
enter name:-qw                                                                 
                                                                               
enter marks1:-78                                                               
                                                                               
enter marks2:-67                                                               
                                                                               
enter the score:-2                                                             
                                                                               
enter rollno:-2
                                                                               
enter name:-xcv
                                                                               
enter marks1:-23                                                               
                                                                               
enter marks2:-22                                                               
                                                                               
enter the score:-3                                                             
                                                                               
1:built a master table                                                         
2:calculate total of marks and grade                                           
3:display the details of all ascending oeder of marks                          
4:exit
enter your choice:-2

1:built a master table
2:calculate total of marks and grade
3:display the details of all ascending oeder of marks
4:exit
enter your choice:-3

rno     name    marks1  marks2  totalmarks  grade       score

2       xcv     23      22      45              c               3
1       qw      78      67      145             A               2
1:built a master table
2:calculate total of marks and grade
3:display the details of all ascending oeder of marks
4:exit
enter your choice:-4
*/

No comments: