# include<stdio.h>
# include<string.h>
# include<stdlib.h>
struct user
//定义用户结构体
{
char username[20];
char password[20];
};
struct student
//定义学生信息结构体
{
int num;
char name[20];
float score[5];
int classs;
char subject[20];
};
struct user user[3]={{"admin","111"},{"andy","222"},{"bob","333"}};
struct student s[5]={
101,"li",{65,66,78,90,87},1101,"软工",
102,"wang",{65,66,78,90,87},1101,"通信",
103,"yan",{87,59,87,86,92},1102,"通信",
104,"ding",{99,98,86,93,92},1101,"软工",
105,"zhang",{65,66,78,90,87},1102,"软工"};
void login(char a[],char b[])
//定义登陆函数
{
system("cls");
//运行前清屏
void index();
int i,count=0;
for(i=0;i<3;i++)
if(strcmp(a,user[i].username)==0&&strcmp(b,user[i].password)==0)
{printf("登陆成功!\n");index();exit(1);}
else
//如果输不正确,提示登录失败
{
printf("登陆失败\n");
count++;
//count用来计数
system("cls");
}
//超过三次退出程序
if(count>=3)
{
printf("登陆失败,请稍后再试\n");
exit(1);
}
}
void main()
{
char a[20],b[20];
printf("\t\t\t\t学生成绩管理系统\n");
printf("********************************************************************************\n");
printf("\t\t\t\t【用户登陆】\n");
printf("\n\n");
printf("\t\t用户名:");
gets(a);
printf("\t\t密码:");
gets(b);
login(a,b);
//调用login函数
}
void index()
//定义索引函数
{
void numquery();
void classquery();
void subquery();
int n;
system("cls");
printf("\n\n\n\n\n\n");
//运行前清屏
printf("\t\t**************学生成绩管理系统登陆成功*************\n");
//菜单选择界面
printf("\t\t
1. 学号查询
\n");
printf("\t\t
2. 班级查询
\n");
printf("\t\t
3. 专业查询
\n");
printf("\t\t
0. 退出
\n");
printf("\t\t***************************************************\n");
printf("\t\t请选择操作(0-3):");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) numquery();
//输入1调用numquery函数
if(n==2) classquery();
//输入2调用classquery函数
if(n==3) subquery();
//输入3调用subquery函数
}
void numquery()
//定义学号查询函数
{
int i,n,m;
system("cls");
//运行前清屏
printf("*********************************学号查询***************************************\n");
printf("请输入要查询的学号:101-105\n");
scanf("%d",&m);
printf("学号\t姓名\t微积分\t物理\tC语言\t英语\t概率\t班级\t专业\n");
for(i=0;i<5;i++)
if(m==s[i].num)
printf("%4d\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].score[3],s[i].score[4],s[i].classs,s[i].subject);
for(i=0;i<5;i++)
if(m==s[i].num)
{ printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) numquery();
if(n==2) index();
exit(1);}
printf("该学号不存在!\n");
printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) numquery();
if(n==2) index();
}
void classquery()//班级查询函数
{system("cls"); //运行前清屏
void highscore();
void lowscore();
void average();
void paixu();
int i,m,n;
printf("********************************班级查询******************************\n");
printf("请输入要查询的班级:1101或1102\n");
scanf("%d",&m);
printf("学号\t姓名\t微积分\t物理\tC语言\t英语\t概率\t班级\t专业\n");
for(i=0;i<5;i++)
if(m==s[i].classs)
printf("%4d\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].score[3],s[i].score[4],s[i].classs,s[i].subject);
for(i=0;i<5;i++)
if(m==s[i].classs )
{ printf("\n\n\n\n\n\n");
printf("\t\t\t1.成绩排序\t2.平均分\n");
printf("\t\t\t3.最高分
\t4.最低分\n");
printf("\t\t\t5.继续查询\t6.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-6)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) {paixu();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
if(n==2) {average();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
if(n==3){ highscore();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
if(n==4){ lowscore();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
if(n==5) {classquery();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
if(n==6){ index();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();}
exit(1);
}
printf("该班级不存在!\n");
printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) classquery();
if(n==2) index();
}
void subquery()
//专业查询函数
{system("cls");
//运行前清屏
void highscore();
void lowscore();
void average();
void paixu();
int i,n;
char m[20];
printf("****************************专业查询*******************************\n");
printf("请输入要查询的专业:软工或通信\n");
scanf("%s",&m);
printf("学号\t姓名\t微积分\t物理\tC语言\t英语\t概率\t班级\t专业\n");
for(i=0;i<5;i++)
if(strcmp(m,s[i].subject)==0)
printf("%4d\t%s\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6.2f\t%6d\t%s\n",
s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].score[3],s[i].score[4],s[i].classs,s[i].subject);
for(i=0;i<5;i++)
if(strcmp(m,s[i].subject)==0)
{
printf("\n\n\n\n\n");
printf("\t\t\t1.成绩排序\t2.平均分\n");
printf("\t\t\t3.最高分
\t4.最低分\n");
printf("\t\t\t5.继续查询\t6.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-6):");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) {paixu();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();}
if(n==2) {average();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();}
if(n==3) {highscore();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();}
if(n==4){ lowscore();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();}
if(n==5) {classquery();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1)subquery();
if(n==2) index();}
if(n==6) {index();printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();}
exit(1);}
printf("该专业不存在!\n");
printf("\n");
printf("\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) subquery();
if(n==2) index();
}
void highscore()
{
system("cls"); /*运行前清屏*/
int i,j,n;
float max;
printf("==============================每门成绩的最高分=============================\n");
printf("\n\n\n\n\n");
printf("\t\t微积分\t物理\tc语言\t英语\t概率\n");
printf("\t\t");
for(j=0;j<5;j++)
{max=0;
for(i=0;i<5;i++)
if(max>s[i].score[j]);
else max=s[i].score[j];
printf("%6.2f\t",max);}
printf("\n");
printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) highscore();
if(n==2) index();
}
void lowscore()
{system("cls");
//运行前清屏
int i,j,n;
float min;
printf("================================每门成绩的最低分==============================\n");
printf("\n\n\n\n\n");
printf("\t\t微积分\t物理\tc语言\t英语\t概率\n");
printf("\t\t");
for(j=0;j<5;j++)
{min=100;
for(i=0;i<5;i++)
if(min<s[i].score[j]);
else min=s[i].score[j];
printf("%6.2f\t",min);}
printf("\n");
printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) lowscore();
if(n==2) index();
}
void average()
//均值函数
{system("cls");
//运行前清屏
int i,j,n;
float m,sum=0;
printf("====================================每门成绩的平均分============================\n");
printf("\n\n\n\n\n");
printf("\t\t微积分\t物理\tc语言\t英语\t概率\n");
printf("\t\t");
for(j=0;j<5;j++)
{sum=0;
for(i=0;i<5;i++)
sum=sum+s[i].score[j];
m=sum/5.0;
printf("%6.2f\t",m);}
printf("\n");
printf("\n\n\n\n\n\n");
printf("\t\t\t1.继续查询\n");
printf("\t\t\t2.返回上一级菜单\n");
printf("\t\t\t0.退出系统\n");
printf("请选择下一步操作:(0-2)\n");
scanf("%d",&n);
if(n==0) exit(1);
if(n==1) average();
if(n==2) index();
}
void paixu()
//排序函数
{system("cls");
//运行前清屏
int i,j,k;
float t;
printf("各科成绩按从高到低排序为:\n\n");
printf("微积分\t");
{for(i=0;i<5;i++)
{k=i;
for(j=i+1;j<5;j++)
if(s[j].score[0]>s[k].score[0])
k=j;
if(k!=i)
{t=s[i].score[0];s[i].score[0]=s[k].score[0];s[k].score[0]=t;}
printf("%6.2f\t",s[i].score[0]);
}
printf("\n");}
printf("物理\t");
{for(i=0;i<5;i++)
{k=i;
for(j=i+1;j<5;j++)
if(s[j].score[1]>s[k].score[1])
k=j;
if(k!=i)
{t=s[i].score[1];s[i].score[1]=s[k].score[1];s[k].score[1]=t;}
printf("%6.2f\t",s[i].score[1]);
}
printf("\n");}
printf("c语言\t");
{for(i=0;i<5;i++)
{k=i;
for(j=i+1;j<5;j++)
if(s[j].score[2]>s[k].score[2])
k=j;
if(k!=i)
{t=s[i].score[2];s[i].score[2]=s[k].score[2];s[k].score[2]=t;}
printf("%6.2f\t",s[i].score[2]);
}
printf("\n");}
printf("英语\t");
{for(i=0;i<5;i++)
{k=i;
for(j=i+1;j<5;j++)
if(s[j].score[3]>s[k].score[3])
k=j;
if(k!=i)
{t=s[i].score[3];s[i].score[3]=s[k].score[3];s[k].score[3]=t;}
printf("%6.2f\t",s[i].score[3]);
}
printf("\n");}
printf("概率\t");
{for(i=0;i<5;i++)
{k=i;
for(j=i+1;j<5;j++)
if(s[j].score[4]>s[k].score[4])
k=j;
if(k!=i)
{t=s[i].score[0];s[i].score[4]=s[k].score[4];s[k].score[4]=t;}
printf("%6.2f\t",s[i].score[4]);
}
printf("\n");}
}