学生成绩管理系统
按班为单位保存一个存储学生纪录
我是初学者,下边是我改的程序但是还有上边一个问题搞不定。希望大虾们帮忙修改一下
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int INDEX[32];
struct STUDENT
{
int id,age,physical,math,english;
char name[21];
}students[32];
void page_title(char *menu_item)
{
clrscr();
printf(">>> <<<\n\n- %s -\n\n",menu_item);
}
void return_confirm(void)
{
printf("\n an ren yi jian fan hui ……\n");
getch();
}
void student_new(void)
{
int n;
page_title("lu ru xue sheng ji ben xin xi");
for(n=0;n<32;n++)
if(students[n].id==0) break;
printf("xue hao:");
scanf("%d",&students[n].id);
printf("xing ming:");
scanf("%s",&students[n].name);
printf("nian ling:");
scanf("%d",&students[n].age);
return_confirm();
}
int search_id(void)
{
int n,i;
printf("xu hao:");
scanf("%d",&i);
for(n=0;n<32;n++)
{
if(students[n].id==i&&students[n].id!=0)
{
printf("xue hao:%d\n",students[n].id);
printf("xing ming:%s\n",students[n].name);
printf("nian ling:%d\n",students[n].age);
return n;
}
}
printf("\nxue hao cuo wu.\n");
return -1;
}
void student_del(void)
{
int n;
page_title("shan chu xue sheng ji lu");
if((n=search_id())!=-1) students[n].id=0;
printf("\n!yi shan chu.\n");
return_confirm();
}
void student_edit(void)
{
int n;
page_title("bian ji xue shen xin xi");
if((n=search_id())!=-1)
{
printf("\nqing shu ru xin xin xi:\nxue hao:");
scanf("%d",&students[n].id);
printf("xing ming:");
scanf("%s",&students[n].name);
printf("nian ling:");
scanf("%d",&students[n].age);
}
return_confirm();
}
void score_input(void)
{
int s,n,t;
page_title("lu ru cheng ji");
printf("\nqing xuan ze ke mu\n1-wu li 2-shu xue 3-ying yu\n");
scanf("%d",&s);
for(n=0;n<32;n++)
{
if(students[n].id!=0)
{
printf("xue hao:%d xing ming:%s cheng ji:",students[n].id,students[n].name);
scanf("%d",&t);
switch(s)
{
case 1 : students[n].physical=t;break;
case 2 : students[n].math=t;break;
case 3 : students[n].english=t;break;
}
}
}
return_confirm();
}
void score_edit(void)
{
int n;
page_title("xiu gai cheng ji");
if((n=search_id())!=-1)
{
printf("wu li:%d shu xue:%d ying yu:%d\n",students[n].physical,students[n].math,students[n].english);
printf("\nqing chong xin shu ru:\nwu li:");
scanf("%d",&students[n].physical);
printf("shu xue:");
scanf("%s",&students[n].math);
printf("ying yu:");
scanf("%d",&students[n].english);
}
return_confirm();
}
void sort_it(char nn)
{
int n,m,p,x,t[32];
for(n=0;n<32;n++)
{
switch(nn)
{
case '1' : t[n]=students[n].id;break;
case '2' : t[n]=students[n].physical;break;
case '3' : t[n]=students[n].math;break;
case '4' : t[n]=students[n].english;break;
case '5' : t[n]=students[n].physical+students[n].math+students[n].english;break;
}
}
for(n=0;n<32;n++)
{
x=0;
p=-1;
for(m=0;m<32;m++)
{
if(t[m]>x)
{
x=t[m];
p=m;
}
}
t[p]=-1;
INDEX[n]=p;
}
}
void browser(void)
{
int n,x;
char k;
sort_it('1');
while(1)
{
page_title("liu lan");
printf("an shu zi jian 1 liu lan huo an0 fan hui\n");
for(n=0;n<32;n++)
{
if(INDEX[n]!=-1)
{
x=INDEX[n];
printf("%d\t%s\t",students[x].id,students[x].name);
printf("%d\t%d\t",students[x].age,students[x].physical);
printf("%d\t%d\t",students[x].math,students[x].english);
printf("%d\n",students[x].physical+students[x].math+students[x].english);
}
}
k=getch();
if(k<'6'&&k>'0') sort_it(k);
else if(k=='0') break;
else continue;
}
}
void main(void)
{
menu: page_title("cai dan");
printf("qiang xuan ze shu zi jian\n\n");
printf("1 lu ru xue sheng xin xi\n2 xiu gai xue sheng xin xi\n");
printf("3 shan chu xue sheng xin xi\n\n4 lu ru cheng ji\n5 xiu gai cheng ji\n\n");
printf("6 liu lan...\n \n0 tui chu\n");
switch(getch())
{
case '1' : student_new();break;
case '2' : student_edit();break;
case '3' : student_del();break;
case '4' : score_input();break;
case '5' : score_edit();break;
case '6' : browser();break;
case '0' : exit(0);
}
goto menu;
}
[此贴子已经被作者于2007-7-18 16:05:16编辑过]