#include
using namespace std;
struct course{
double math;
double computer;
double english;
double physics;
};
struct student{
char name[20];
course cos;
};
void display(student &stu);//显示结构体内容
course calmean(student *pstu,int num);//各科求平均
void main(void){
student stu[]={{"hawkol",90,80,70,60},{"lile",20,30,40,50},{"zhangje",80,90,80,90},{"disha",91,82,73,99}};
course c=calmean(stu,4);
cout<<"name"<<'\t'<<"math"<<'\t'<<"computer"<<'\t'<<"english"<<'\t'<<"physics"<<endl;
for(int i=0;i<4;i++)
display(stu[i]);
cout<<"---------------------------------------------"<<endl;
cout<<"Average"<<'\t'<<c.math<<'\t'<<c.computer<<'\t'<<c.english<<'\t'<<c.physics<<endl;
}
void display(student &stu)
{
cout<<stu.name<<'\t'<<stu.cos.math<<'\t'<<stu.cos.computer<<'\t'<<stu.cos.english<<'\t'<<stu.cos.physics<<endl;
}
course calmean(student *pstu,int num)
{
course c={0,0,0,0};
if (num<=0)
return c;
for(int i=0;i
{
c.math+=pstu[i].cos.math;
c.computer+=pstu[i].cos.computer;
c.english+=pstu[i].cos.english;
c.physics+=pstu[i].cos.physics;
}
c.math/=num;c.computer/=num;c.english/=num;c.physics/=num;
return c;
}