You are on page 1of 2

/* program 2 : program to create student class and calculate avg.

*/

#include<iostream.h>

class student
{
char usn[10],name[20];
int t1,t2,t3;
double avg;

public :
void read()
{
cin>>usn>>name>>t1>>t2>>t3;
calavg();
}
void display()
{
cout<<usn<<"\t"<<name<<" "<<t1<<"\t"<<t2
<<"\t"<<t3<<"\t"<<avg<<endl;
}
void calavg()
{
if(t1<=t2 && t1<=t3)
avg=(t2+t3)/2.0;
else if(t2<=t1 && t2<=t3)
avg=(t1+t3)/2.0;
else
avg=(t1+t2)/2.0;
}
};

int main()
{
student s[10];
int n;
cout<<"enter no. of students [1-10]: ";
cin>>n;
cout<<"\n\nenter "<<n<<" student details..\n"
<<"usn\tname test1\ttest2\ttest3\n"
<<"---------------------------------------------\n";
for(int i=0;i<n;i++)
s[i].read();
cout<<"\n\n"<<n<<" student details..\n\n"
<<"usn\tname test1\ttest2\ttest3\tavg\n"
<<"---------------------------------------------\n";
for(i=0;i<n;i++)
s[i].display();
cout<<"\n\n";
return 0;
}

/* --------- output --------

enter no. of students [1-10]: 4


enter 4 student details..
usn name test1 test2 test3
---------------------------------------------
2bv vishu 20 18 16
2bv venki 18 20 18
2bv rock 22 24 24
2bv vijay 20 22 24

4 student details..

usn name test1 test2 test3 avg


---------------------------------------------
2bv vishu 20 18 16 19
2bv venki 18 20 18 19
2bv rock 22 24 24 24
2bv vijay 20 22 24 23

You might also like