#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10000
#define MAX_UINT 10000
typedef unsigned int UINT ;
typedef struct Student{
UINT id;
char name[50];
int class;
char le;
float ps;
float sy;
float qm;
}grade;
grade a[MAX];
static UINT Amount=0;
void menu_show();
UINT get_choice(UINT a,UINT b);
int chengji_CaiJi();
void chengji_zhuijia();
void chengji_ChaXun();
void chengji_ShanChu();
void chengji_liulan();
int IsReiteration(UINT);
int main() {
UINT number;
while(1)
{
menu_show ();
number=get_choice(0,5);
switch(number)
{
case 1:
system("cls");
chengji_CaiJi();
break;
case 2:
system("cls");
chengji_liulan();
break;
case 3:
system("cls");
chengji_zhuijia();
break;
case 4:
system("cls");
chengji_ShanChu();
break;
case 5:
system("cls");
chengji_ChaXun();
break;
case 0:
printf("谢谢你的使用,再见!\n");
system("pause");
exit(0);
break;
default: printf("Error!\n"); break;
}
}
return 0;
}
void chengji_show()
{
system("cls");
printf(" 欢迎进入学生成绩信息管理系统!\n");
printf("*============================*\n");
printf("* 1. 学生成绩信息的采集 *\n");
printf("* 2. 学生成绩信息的浏览 *\n");
printf("* 3. 学生成绩信息的追加 *\n");
printf("* 4. 学生成绩信息的删除 *\n");
printf("* 5. 学生成绩信息的查询 *\n");
printf("* 0. 退出管理系统 *\n");
printf("*============================*\n");
printf("* 请选择0-5: *");
}
UINT get_choice(UINT a,UINT b)
{
UINT p=0;
while(scanf("%d",&p)!=1||p<a||p>b)
{
system("cls");
printf("你输入错误! (范围 %d~%d)\n",a,b);
system("pause");
printf("请重新输入:");
}
return p;
}
int chengji_caiji()
{
char s[2];
while(1)
{
system("cls");
printf("完成采集学生成绩信息的功能\n");
printf("学生ID:");
a[Amount].id =get_choice(1,MAX_UINT);
if(IsReiteration(a[Amount].id))
{
printf("你输入的学号重复!\n");
system("pause");
return 0;
}
while(getchar()!='\n')
continue;
printf("学生姓名:");
gets(a[Amount].name);
printf("班级:");
printf("%d\n",a[Amount].class);
Amount++;
printf("请问你是否继续?(y/n)");
gets(s);
if(strcmp(s,"n")==0||strcmp(s,"N")==0)
return 0;
}
}
void chengji_zhuijia()
{
char s[2];
while(1)
{
system("cls");
printf("完成追加一个学生的信息的功能\n");
printf("学生ID:");
a[Amount].id=get_choice(1,MAX_UINT);
if(IsReiteration(a[Amount].id))
{
printf("你输入的学生ID重复!\n");
system("pause");
return;
}
while(getchar()!='\n')
continue;
printf("学生姓名:");
gets(a[Amount].name);
printf("班级:");
printf("%d\n",a[Amount].class);
printf("学生id:");
printf("%d\n",a[Amount].id);
Amount++;
printf("输入成功\n");
printf("请问你是否继续?(y/n)");
gets(s);
if(strcmp(s,"n")==0||strcmp(s,"N")==0)
return;
}
}
void chengji_ChaXun()
{
char s[2];
UINT choice=0;
UINT pid=0;
UINT pclass;
char pname[40];
while(1)
{
system("cls");
printf("*完成学生成绩信息的查询功能*\n");
printf("* 学生成绩信息的查询 *\n");
printf("*==========================*\n");
printf("* 1. By学生id *\n");
printf("* 2. By学生姓名 *\n");
printf("* 3. By学生班级 *\n");
printf("* 0. 返回上一级 *\n");
printf("*请输入你的选择(0~2)[ ] *\b\b");
choice=get_choice(0,2);
switch(choice)
{
case 0:
return;
break;
case 1:
system("cls");
printf("学生id:");
pid=get_choice(1,MAX_UINT);
SearchByNum(pid);
break;
case 2:
system("cls");
while(getchar()!='\n')
continue;
printf("请输入学生姓名:");
gets(pname);
SearchByName(pname);
break;
case 3:
system("cls");
printf("请输入班级:");
pclass=get_choice(1,MAX_UINT);
SearchByNum(pclass);
break;
default: printf("你输入错误!\n");
break;
}
printf("请问你是否继续?(y/n)");
gets(s);
if(strcmp(s,"n")==0||strcmp(s,"N")==0)
return;
}
}
void chengji_ShanChu()
{
printf("完成学生成绩信息都删除功能\n");
UINT pid=0;
UINT i,j;
printf("请输入你要删除的学生信息ID:");
pid=get_choice(1,MAX_UINT);
for(i=0;i<Amount;++i)
if(pid==a[i].id)
break;
if(i==Amount)
{
printf("Error! 你输入的学生成绩信息ID不存在!\n");
system("pause");
return;
}
for(j=i;j<Amount-1;++j)
a[j]=a[j+1];
Amount--;
}
void chengji_liulan()
{
printf("完成学生成绩信息的浏览功能\n");
UINT i;
for(i=0;i<Amount;++i)
{
printf("%s\t%d\t%s\t%f\t%f\t%f\n",a[i].name,a[i].id,a[i].le,a[i].ps,a[i].sy,a[i].qm);
}
printf("学生总共%d人\n",Amount);
system("pause");
}