Ask a Teacher



develope program for th following using classes and objects: define a class student with data member function to:(1)input the values,(2)calculate the total scores and (3)display the information with total score and percentage. create an object and demonstrate these functions.the execution of the programe should be continued as long as the user wants

#include<iostream.h>

#include<conio.h>

class grade

{

int r,g,t,i,total,m[5];

char a[15];

float per;

public:

void process();

};

void grade::process()

{

total=0;

cout<<"Enter the name of the student: "??;

cin>>a;

cout<<?"Enter the roll number of the student:"??;

cin>>r;

cout<<"Enter marks obtained in five subjects: "<<endl;

for(i=0;i<5;i++)

{

cout<<"Enter marks in'<<i+1<<'? subject: ";

cin>>t;

if(t<=100)

m[i]=t;

else

{

cout<<"Marks should not exceed 100\n";

i=i-1;

}

}

for(i=0;i<5;i++)

total=total+m[i];

per=(total/500.0)*100;

cout<<'?\nNAME\tROLLNO\tTOTAL\tPERCENTAGE\tGRADE\n\nâ? ;

cout<<a<<"\t"<<r<<"?\t"<<total<<"?\t"<<per<<"\t"?;

g=per/10;

switch(g)

{

 

case 9:

case 8:

case 7:

cout<<"Grade A"?;

break;

case 6:

case 5:

cout<<"Grade B"?;

break;

case 4:

cout<<"Grade C"?;

break;

default:

cout<<"Grade D"?;

}

}

void main()

{

grade g1;

clrscr();

g1.process();

getch();

}


comments powered by Disqus