求救:编一个C++程序

来源:百度知道 编辑:UC知道 时间:2024/05/24 11:02:13
有5个学生,每个学生的数据机构包括学号.姓名.年龄.C++成绩.数学成绩.总平均分,从键盘输入5个学生的学号.姓名.3门课的成绩,计算3门课的总平均分,最后将5个学生的数据输出. 要求:1.设学生数据为结构体型STUDENT;2.用二个函数来实现:(1).计算总平均分;(2).输出学生数据

#include"stdio.h"

#define MAX 5

struct STU
{
int num;
char name[20];
int age;
int score[3];
};

void input(struct STU s[])
{
int i;
for(i=0;i<MAX;i++)
{
printf ("%d:\tNO: ",i+1);
scanf("%d",&(s[i].num));
getchar();
printf ("\tname: ");
gets(s[i].name);
printf ("\tAge: ");
scanf("%d",&(s[i].age));
printf ("\tEnglish: ");
scanf("%d",&(s[i].score[0]));
printf ("\tMath: ",i);
scanf("%d",&(s[i].score[1]));
printf ("\tC++: ");
scanf("%d",&(s[i].score[2]));
printf ("\n\n");
}
}

void out_ave(struct STU s[])
{
int i;
float ave1=0, ave2=0, ave3=0;

for(i=0;i<MAX;i++) {