看代码:
#include<iostream.h>
struct STUDENT
{
int no;
float score[3];
float edit[3];
float total,ave;
float alledit;
};
STUDENT stu[3]={
{1001,34,56,78,90,98,78},
{1002,67,78,89,90,98,79},
{1003,67,89,98,68,79,90}
};
int main()
{
for(int i=0;i<sizeof(stu)/sizeof(STUDENT);i++)
{
stu[i].total=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
stu[i].ave=stu[i].total/3.0;
stu[i].alledit=stu[i].edit[0]+stu[i].edit[1]+stu[i].edit[2];
cout<<"stu["<<i<<"].total="<<stu[i].total<<endl;
cout<<"stu["<<i<<"].ave="<<stu[i].ave<<endl;
cout<<"stu["<<i<<"]alledit="<<stu[i].alledit<<endl;
cout<<endl;
}
return 0;
}
看结果: