#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define N 100
struct stu{
char number[8];
char name[8];
char sex[2];
int yw,sx,yy,sum;
float ave;
};
void creat(struct stu score[]);
void add(struct stu score[]);
void search(struct stu score[]);
void alter(struct stu score[]);
void del(struct stu score[]);
void sta(struct stu score[]);
void sort(struct stu score[]);
static int m=0;
void main()
{
int p;
struct stu score[50];
printf(" 学生成绩管理系统\n");
printf("1.创建学生的资料 2.追加学生的资料\n");
printf("3.查询学生的资料 4.修改学生的资料\n");
printf("5.删除学生的资料 6.统计学生的资料\n");
printf("7.对学生资料进行排序\n");
printf("***欢迎进入成绩管理系统,请选择您所要的操作(按任意键退出):");
scanf("%d",&p);
while(p>=1&&p<=7)
{
switch(p)
{
case 1:creat(score);break;
case 2:add(score);break;
case 3:search(score);break;
case 4:alter(score);break;
case 5:del(score);break;
case 6:sta(score);break;
case 7:sort(score);break;
default :exit(0);
}
printf("请选择您所要的操作:");
scanf("%d",&p);
}
}
void creat(struct stu score[])
{
int i=0,k=1;
while(k!=0)
{
printf("请依次输入第%d个学生的学号、姓名、性别、语文、数学、英语:\n",i+1);
scanf("%s%s%s%d%d%d",
score[i].number,score[i].name,score[i].sex,&score[i].yw,&score[i].sx,
&score[i].yy,&score[i].sum,&score[i].ave);
m++;
printf("是否继续(0表示结束)");
scanf("%d",&k);
}
}
void add(struct stu score[])
{
int i;
int q;
printf("要添加的人数:");
scanf("%d",&q);
for(i=0;i<q;i++)
{
printf("请依次输入要添加的第%d个学生的学号、姓名、性别、语文、数学、英语:\n",i+1);
scanf("%s%s%s%d%d%d",
score[i].number,score[i].name,score[i].sex,&score[i].yw,&score[i].sx,
&score[i].yy);
m=m+q;
}
}
void search(struct stu score[])
{
char q[8];int i;
printf("输入要查询的学生的姓名或学号:");
gets(q);
for(i=0;i<m;i++)
{
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
printf("%s%s%s%d%d%d%f%f",
score[i].number,score[i].name,score[i].sex,score[i].yw,score[i].sx,score[i].yy,score[i].sum,score[i].ave);
}
}
void alter(struct stu score[])
{
char q[8];int i;
printf("资料要修改的学生的姓名或学号:");
gets(q);
for(i=0;i<m;i++)
{
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
{
printf("请重新依序输入该学生资料(学号、姓名、性别、语文、数学、英语):");
scanf("%s%s%s%d%d%d",
&score[i].number,&score[i].name,&score[i].sex,&score[i].yw,&score[i].sx,
&score[i].yy);
}
}
}
void del(struct stu score[])
{
char q[8];
int i,j;
printf("要删除的学生的姓名或学号:");
gets(q);
for(i=0;i<m;i++){
if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
{
for(j=i;j<m-1;j++)
score[j]=score[j+1];
m-=1;
}
}
}
void sta(struct stu score[])
{
int i;
for(i=0;i<m;i++)
{
score[i].sum=score[i].yw+score[i].sx+score[i].yy;
score[i].ave=(float)score[i].sum/3;
}
}
void sort(struct stu score[])
{
int i,j;
struct stu t;
for(i=0;i<m-1;i++)
{
for(j=i+1;j<m;j++)
{
if(score[i].ave<score[j].ave)
t=score[i],score[i]=score[j],score[j]=t;
}
}
}
////creat函数中我总是要输入k值判断是否继续,能否换个方式优化一下,连续输入,最后判断一次就好。功能5,6,7,运行不了,其他正常 ,实在不知道原因。