### Question ::

                           Define a Class "student" with roll number, name and marks in 3 tests of a subject.Declare an array of 10 "student" objects.Using Appropriate Functions, Find the Average of Two Better Marks For Each Student. Print the Roll Number , Name and the Average marks of all the students.



###Solution ::




[ Write down headers yourself. ]




class student

{

public:

long roll;

char name[12];

float mark[3];

float in1,in2;

float average;

void getdata()


{
int i;

cout<<"\n\nEnter name:"; cin>>name;

cout<<"\n\nEnter Roll:"; cin>>roll;

cout<<"\n\nEnter Numbers of three subjects:" ; for(i=0;i<3;i++) { cin>>mark[i];

}

if(mark[0]>mark[1]||mark[0]>mark[2])

{ in1=mark[0];

if(mark[1]>mark[2])

in2=mark[1];

else

in2=mark[2];

}

else

{

if(mark[1]>mark[2])

{in1=mark[1]; in2=mark[2];}

else

{in1=mark[2]; in2=mark[1];}

}

average=float(in1+in2)/2;

}



void display()

{

cout<<"\n\nNAME :: "<

cout<<"\n\nROLL :: "<

cout<<"\n\nAVERAGE OF TWO BETTER MARKS :: "<

}

};

void main()

{ int i,j;

clrscr();

student s[10]; //You can change the number '10'. This is the number of students.
for(i=0;i<10;i++) //If you change student number you have to change '10' according
s[i].getdata();
//to the number of students in these two loops also.
for(j=0;j<10;j++)

s[j].display();

getch();

}

0 comments