求助,为什么在case1中,当输入完学生的相关信息后,自定义函数void Calate1功能没有实现
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#define MAX_STUDENT 30
#define MAX_COURSE 6
typedef struct student
{
long studentID;
char studentname[10];
int score[MAX_COURSE];
int total;
float aver;
}STUDENT;
void menu();
void Add(int *pm,int*pn);
void Inputscore(STUDENT stu[],int m,int n);
void Calate2(STUDENT stu[],int m,int n);
void Calate1(STUDENT stu[],int m,int n);
int main()
{
int k;
int n,m;
int *pm=&m,*pn=&n;
STUDENT stu[MAX_STUDENT];
printf("\t\t***************欢迎使用学生成绩管理系统*******************\n");
menu();
printf("Please enter your choice:\n");
scanf("%d",&k);
switch(k)
{
case 1:
Add(&m,&n);
Inputscore(stu,m,n);
Calate1(stu,m,n);
break;
case 2:
Calate1(stu,m,n);
break;
case 3:
Calate2(stu,m,n);
break;
}
return 0;
}
void menu()
{
printf("1.Input record\n");
printf("2.Caculate total and average score of every course\n");
printf("3.Caculate total and average score of every student\n");
printf("4.Sort in decending order by total score of every student\n");
printf("5.Sort in ascending order by total score of every student\n");
printf("6.Sort in ascending order by number\n");
printf("7.Sort in ascending order by name\n");
printf("8.Search by number\n");
printf("9.Search by name\n");
printf("10.Statistic analysis for every course\n");
printf("11.List record\n");
printf("0.Exit\n");
}
void Add(int *pm,int*pn)//输入学生人数和考试科目
{
printf("请输入考试科目");
scanf("%d",pm);
printf("请输入学生人数");
scanf("%d",pn);
}
void Inputscore(STUDENT stu[],int m,int n)//1、输入学生的 学号,姓名,及考试成绩
{
int i,j;
for(i=0;i<n;i++)
{
printf("Input record%d\n",i+1);
printf("请输入学生学号");
scanf("%ld",&stu[i].studentID);
printf("请输入学生姓名");
scanf("%s",&stu[i].studentname);
printf("请输入学生成绩");
for(j=0;j<m;j++)
{
scanf("%ld",&stu[i].score[j]);
}
}
}
void Calate2(STUDENT stu[],int m,int n)//3、计算每个学生的平均分及总分
{
int i,j;
int sum[MAX_STUDENT];
for(i=0;i<n;i++)//使所用学生进入循环
{
sum[i]=0;
for(j=0;j<m;j++)//所有科目进入循环
{
sum[i]=sum[i]+stu[i].score[j];
}
stu[i].total=sum[i];
stu[i].aver=(float)sum[i]/m;
}
}
void Calate1(STUDENT stu[],int m,int n)//2、计算每门课目的平均分及总分
{
int sum[MAX_COURSE];
float aver[MAX_COURSE];
int i,j;
for(j=0;j<m;i++)//单个课目 考试科目进入循环
{
sum[j]=0;
for(i=0;i<n;i++)//所有学生进入循环
{
sum[j]=sum[j]+stu[i].score[j];
}
aver[j]=(float)sum[j]/m;
}
printf("Sumofcourse\t");//打印
for(j=0;j<m;j++)
{
printf("%4d\t",sum[j]);
}
printf("\nAverofcourse\t");
for(j=0;j<m;j++)
{
printf("%f\t",aver[j]);
}
}
/*void Sumsortdecen(STUDENT stu[],int n)//按总分由高到低排出名次表
{
int i,j,k;
STUDENT t;
for(i=0;i<n-1;i++)//
{
k=i;
for(j=i+1;j<n;j++)//
{
if(stu[j].total>stu[k].total)
{
k=j;
}
}
if(k!=i)
{
t=stu[i];
stu[i]=stu[k];
stu[k]=t;
}
for(i=0;i<n;i++)//打印出学生信息
{
printf("ID:%ld,NAME:%s,score:%d",stu[i].studentID,stu[i].total);
}
}
void Sumsortascen(STUDENT stu[],int n)//按总分由低到高排出名次表
{
int i,j,k;
STUDENT t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(stu[j].total<stu[k].total)
{
k=j;
}
}
if(k!=i)
{
t=stu[i];
stu[i]=stu[k];
stu[k]=t;
}
for(i=0;i<n;i++)//打印出学生信息
{
printf("ID:%ld,NAME:%s,score:%d",stu[i].studentID,stu[i].total);
}
}
void Denumber(STUDENT stu[],int m,int n)//6
{
int i,j,k;
STUDENT t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(stu[k].studentID>stu[j].studentID)
{
k=j;
}
if(k!=i)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
for(i=0;i<n;i++)
{
printf("ID:%ld,name:%s\n",stu[i].studentID,stu[i].studentname);
for(j=0;j<m;j++)
{
printf("Project%d,score:%d\n",j+1,stu[i].score[j]);
}
}
}
}
}
void Dicts(STUDENT stu[],int m,int n)//7
{
int i,j;
STUDENT t;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(stu[i].studentname,stu[j].studentname)>0)
{
t=stu[k];
stu[k]=stu[i];
stu[i]=t;
}
for(i=0;i<n;i++)
{
printf("ID:%ld,name:%s\n",stu[i].studentID,stu[i].studentname);
for(j=0;j<m;j++)
{
printf("Project%d,score:%d\n",j+1,stu[i].score[j]);
}
}
}
}
}
void Searchbynum(STUDENT stu[],int n ,int m,int x)
{
int i,j,c=1,find=0,k=0;
for(i=0;i<n;i++)
{
if(stu[i].studentID==x)
{
k=i;
find=1;
break;
}
if(find==0)
printf("NOT FIND\n");
else
{
for(j=0;j<n:j++)
{
if(stu[j].total>stu[k].total)
c++;
}
printf("ID:%ld,NAME:%s\n",stu[k].studentID,stu[k].studentname);
for(j=0;j<m;j++)
printf("Prjoect:%d,score%d\n",j+1,stu[k].score[j]);
printf("All score :%d,Order:%d\n",stu[k].total,c);
}
}*/
[此贴子已经被作者于2016-2-22 13:38编辑过]