C语言:输入一批学生的n门课成绩,可以输出每个学生的平均分和每门课程的平均分,找出平均分最高的学生。

要求设计7个函数,每个函数完成一项功能:主函数main()、成绩输入input_stu()、数据计算calc_data()、计算学生平均分avr_stu()、计算课程平均分avr_cor()、数据查找(查找最高分)highest()和输入成绩output_stu()。
要有注释,不用指针,不能太复杂,就用这些函数就行。
我们只教了基本语句、函数和数组。。。你们写得这些看不懂啊。。。

函数名自己改下,这是我以前写的。你就自己参考一下就算了
#include<stdio.h>
#include<stdlib.h>
#define NUM1 3 // 学生人数
#define NUM2 3 //统计科目
struct student //定义了个struct student 结构体
{long num; //学号
char name[5]; //姓名
float score[NUM2]; //统计科目的分数
float stu_aver; //一个(某个)学生的平均成绩
};
void input(struct student *pstu) //自定义输入函数input
{int i;

printf("请输入相关学生的信息:\n");
printf("学号 姓名 语文 数学 外语\n");
for(i=0;i<NUM1;i++,pstu++)
{ scanf("%ld%s%f%f%f",&pstu->num,pstu->name,&pstu->score[0],&pstu->score[1],&pstu->score[2]);
printf("\n");
}
}

void output(struct student *pstu,float *psub, int x) //自定义输出函数
{int i; struct student *p=pstu;
printf("每个学生的平均分如下:\n");
for(i=0;i<NUM1;i++,pstu++)
printf("%5s%10.2f\n",pstu->name,pstu->stu_aver);
pstu=p; //将pstu置原,若不置原,会影响后面的输出,值得注意
printf("其中平均分最大的是:%s %.2f \n", (pstu+x)->name,(pstu+x)->stu_aver); //x表示:序号为x的学生的平均值最大
printf("该班的各科平均成绩依次如下:\n");
for(i=0;i<NUM2;i++,psub++)
printf("%.2f\n",*psub);
return;

}
void stu_aver(struct student *pstu) //自定义“学生平均成绩”函数
{ int i;
for( i=0;i<NUM1;i++,pstu++)
pstu->stu_aver=(pstu->score[0]+pstu->score[1]+pstu->score[2])/NUM2;
}
void sub_avermain(struct student *pstu,float *psub) //自定义“科目平均成绩”函数
{ int i;
for( i=0;i<NUM2;i++,psub++)
*psub=(pstu->score[i]+(pstu+1)->score[i]+(pstu+2)->score[i])/NUM1;

}
int max_stu_aver(struct student *pstu) //自定义“最大学生平均成绩”函数
{int i,k=0; //注意,k要预先赋初始值为0.
float max;
max=pstu->stu_aver;
for(i=0;i<NUM1;i++,pstu++)
if(pstu->stu_aver>max) //注意,if语句有可能不执行,所以,k要预先赋初始值0
{max=pstu->stu_aver;k=i;}
return(k);
}
int main()
{
int m;
float sub_aver[NUM2];
float *psub;
struct student stu[NUM1],*pstu;
pstu=stu;
psub=&sub_aver[0];
input(pstu); //注意下面的pstu每调用完,要置原
pstu=stu;
stu_aver(pstu);
pstu=stu;
sub_avermain(pstu,psub);
pstu=stu;psub=&sub_aver[0];
m=max_stu_aver(pstu);
pstu=stu;
output(pstu,psub,m);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-22
我实现了输入输出,其他就先不做了
//不用结构体,直接指针数组实现
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * a[50]; //只能容纳50个学生学号
char * b[50]; //容纳50个学生姓名
char * c[10]; //容纳学习的课程
double d[10][50]; //容纳所有学生的所有成绩
int kc; //课程数量
int count; //学生总人数
input_stu() //成绩输入input_stu()
{
int i=0,m;
int melody=0;
char ch;
char zhu[10];
while(1)
{
if(0==melody)
{
printf("输入学号:");
gets(zhu);
a[i]=(char *)malloc(sizeof(char)*(strlen(zhu)+1));
strcpy(a[i],zhu);
printf("输入姓名:");
gets(zhu);
b[i]=(char *)malloc(sizeof(char)*(strlen(zhu)+1));
strcpy(b[i],zhu);
for(m=0;m<kc;m++)
{
printf("输入%s的%s成绩:",a[i],c[m]);
scanf("%lf",&d[i][m]);
}
}
fflush(stdin);
printf("是否继续添加Y/N:");
ch=getchar();
fflush(stdin);
if('y'==ch||'Y'==ch)
{
melody=0;
i++;
}
else if('n'==ch||'N'==ch)
{
count=i+1;
break;
}
else
{
printf("输入错误!\n");
melody=1;
}
}
}
calc_data() //数据计算calc_data()
{
}
avr_stu() //计算学生平均分avr_stu()
{
}
avr_cor() //计算课程平均分avr_cor()
{
}
highest() //数据查找(查找最高分)highest()
{
}
output_stu() //输入成绩output_stu()
{
int i,m;
for(i=0;i<count;i++)
{
printf("学号:%s,姓名:%s:\n",a[i],b[i]);
for(m=0;m<kc;m++)
{
printf(" %s:%.4f\n",c[m],d[i][m]);
}
}
}
int main()
{
int j=0;
int melody=0;
char zhu[10];
while(1)
{
char ch;
if(melody==0)
{
printf("输入课程:");
gets(zhu);
c[j]=(char *)malloc(sizeof(char)*(strlen(zhu)+1));
strcpy(c[j],zhu);
j++;
}
printf("是否继续添加Y/N:");
ch=getchar();
fflush(stdin);
if('y'==ch||'Y'==ch)
{
melody=0;
}
else if('n'==ch||'N'==ch)
{
break;
}
else
{
printf("输入错误!\n");
melody=1;
}
}
kc=j;
input_stu();
output_stu();
return 0;
}
第2个回答  2013-04-22
#include<stdio.h>
#include<stdlib.h>
#define NUM1 3
#define NUM2 3
struct student
{long num;
char name[5];
float score[NUM2];
float stu_aver; //
};
void input(struct student *pstu)
{int i;

printf("请输入相关学生的信息:\n");
printf("学号 姓名 语文 数学 外语\n");
for(i=0;i<NUM1;i++,pstu++)
{ scanf("%ld%s%f%f%f",&pstu->num,pstu->name,&pstu->score[0],&pstu->score[1],&pstu->score[2]);
printf("\n");
}
}
第3个回答  2013-04-19
这个不难,我觉得还是不要懒着,自己动手比较好
第4个回答  2013-04-21
不错悲催 13阿萨德