求修改 学生成绩管理系统
vc6.0可以运行,但好多错误。。。哪位大神帮忙修改一下
我已经改的自己都不认识自己了
#include <stdio.h>
#define M 50
struct student
{
long num;
char name[10];
int chinese,english,math,sum,average;
};
void new_student(struct student students[]);
void search_student(struct student students[],int num);
void row_student(struct student students[]);
void delete_student(struct student students[],int num);
void modify_student(struct student students[],int num);
int count=0;
main()
{
int choice,num;
struct student students[M];
printf("╔══════学生成绩管理系统══════╗\n");
printf("║ ║\n");
printf("║ ║\n");
printf("║ 1.录入 2.查找 ║\n");
printf("║ ║\n");
printf("║ 3.排名 4.删除 ║\n");
printf("║ ║\n");
printf("║ 5.修改 0.退出 ║\n");
printf("║ ║\n");
printf("╚════════════════════╝\n");
printf("\n");
do
{
printf(" * 1:输入 2:查询 3:排序 4:删除 0:退出 *\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
new_student(students);
break;
case 2:
printf("请输入查询学生的学号:");
scanf("%d",&num);
search_student(students,num);
break;
case 3:
row_student(students);
break;
case 4:
printf("请输入要删除学生的学号:");
scanf("%d",&num);
delete_student(students,num);
break;
case 5:
printf("请输入要修改的学生学号:");
scanf("%d",&num);
modify_student(students,num);
case 0:
break;
default :
printf("输入有误,请重新选择\n");
break;
}
}
while(choice!=0);
printf("结束\n");
return 0;
}
/*插入*/
void new_student(struct student students[])
{
struct student s;
if(count==M){
printf("已满\n");
return;
}
printf("请输入第%d个学生学号,姓名,语文,英语,数学成绩:\n",count+1);
scanf("%d%s%d%d%d",s.num,&s.name,&s.chinese,&s.english,&s.math);
s.sum=s.chinese+s.english+s.math;
s.average=s.sum/3.0;
students[count]=s;
count++;
}
/*查询*/
void search_student(struct student students[],int num)
{
int i;
for(i=0;i<count;i++)
{
if(students[i].num==num)
{
printf("学生信息如下:\n");
printf ("学号 姓名 语文 英语 数学 总分 平均分\n");
printf("%-8d%-8s%-8d%-8d%-8d%-8d%-8f\n",students[i].num,students[i].name, students[i].chinese,students[i].english,students[i].math,students[i].sum,students[i].average);
break;
}
else
printf("无此学生信息\n");
}
}
/*排序*/
void row_student(struct student students[])
{
int i,j,index;
struct student temp;
for(i=0;i<count-1;i++)
{
index=i;
for(j=i+1;j<count;j++)
{
if(students[j].sum>students[index].sum)
{
index=j;
temp=students[index];
students[index]=students[i];
students[i]=temp;
}
}
}
printf("成绩排序如下:\n");
printf ("学号 姓名 语文 英语 数学 总分 平均分\n");
for(i=0;i<count;i++)
printf("%-8d%-8s%-8d%-8d%-8d%-8d%-8f\n",students[i].num,students[i].name, students[i].chinese,students[i].english,students[i].math,students[i].sum,students[i].average);
}
/*删除*/
void delete_student(struct student students[],int num)
{
int i;
for(i=0;i<count;i++)
{
if(students[i].num==num)
printf("删除成功\n");
do
{
students[i]=students[i+1];
i++;
}
while(i<count-1);
}
}
/*修改*/
void modify_student(struct student students[],int num)
{
int i;
for(i=0;i<count;i++)
{
if(students[i].num==num)
{
printf("你要修改的学生信息为:\n");
printf ("学号 姓名 语文 英语 数学 总分 平均分\n");
printf("%-8d%-8s%-8d%-8d%-8d%-8d%-8f\n",students[i].num,students[i].name, students[i].chinese,students[i].english,students[i].math,students[i].sum,students[i].average);
printf("-- 请输入新值--\n");
printf("请输入学号:");
scanf("%s",&students[i].num);
getchar();
printf("请输入姓名:");
scanf("%s",&students[i].name);
getchar();
printf("请输入语文成绩:");
scanf("%f",&students[i].chinese);
getchar();
printf("请输入数学成绩:");
scanf("%f",&students[i].math);
getchar();
printf("请输入英语成绩:");
scanf("%f",&students[i].english);
getchar();
students[i].sum=students[i].chinese+students[i].math+students[i].english;
students[i].average=students[i].sum/3.0;
}
else
{
printf("学生不存在!\n");
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}