|
|
#include"stdio.h"
|
|
|
#include"windows.h"
|
|
|
#include"conio.h"
|
|
|
#include"stdlib.h"
|
|
|
#include"string.h"
|
|
|
int menu();
|
|
|
int menu_select();
|
|
|
void tj();
|
|
|
void cx();
|
|
|
int xg();
|
|
|
void xs();
|
|
|
void fd();
|
|
|
void pm();
|
|
|
float fm();
|
|
|
int pass();
|
|
|
int average();
|
|
|
int wenjiandiaochu();
|
|
|
int mima();
|
|
|
int i,j,k,y;
|
|
|
FILE *fp;
|
|
|
struct stu
|
|
|
{
|
|
|
int xh;
|
|
|
char name[30];
|
|
|
float score;
|
|
|
};struct stu s[100];
|
|
|
int main()
|
|
|
{
|
|
|
system("color F4");//亮白,红
|
|
|
system("pause");
|
|
|
int e;
|
|
|
e=mima();
|
|
|
if(e==1)
|
|
|
return 0;
|
|
|
printf("\n");
|
|
|
printf("\t*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
|
|
|
printf("\t* 好嗨哟! *\n");
|
|
|
printf("\t* 恭喜你的人生到达了 *\n");
|
|
|
printf("\t* 学生C语言成绩记录簿系统 *\n");
|
|
|
printf("\t* *^_^* *\n");
|
|
|
printf("\t* *^欢迎使用^* *\n");
|
|
|
printf("\t*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
|
|
|
printf("\n");
|
|
|
menu();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int menu()//菜单
|
|
|
{
|
|
|
|
|
|
int n=0;
|
|
|
char c,a;
|
|
|
n=menu_select();
|
|
|
|
|
|
switch(n)
|
|
|
{
|
|
|
case 0: tj(); break;//添加
|
|
|
case 1: xg(); break;// 修改
|
|
|
case 2: xs(); break;//显示
|
|
|
case 3: cx();break;//查询
|
|
|
case 4: pm();break;//排序
|
|
|
case 5: fm();break;//最高和最低分
|
|
|
case 6: average();break;//平均分
|
|
|
case 7: pass();break;//及格率
|
|
|
case 8: fd();break;//学生成绩分段
|
|
|
case 9: return 0;//结束
|
|
|
}
|
|
|
if(0<=n&&n<=8)
|
|
|
{
|
|
|
printf("是否继续对学生成绩进行管理,是请输入Y,否请输入N\n");
|
|
|
a=getchar();
|
|
|
scanf("%c",&c);
|
|
|
|
|
|
if(c=='y'||c=='Y')
|
|
|
{
|
|
|
system("cls");
|
|
|
menu();
|
|
|
}
|
|
|
|
|
|
while(c!='y'&&c!='Y'&&c!='n'&&c!='N')
|
|
|
{
|
|
|
printf("你的输入怕是有毛病,现在请重新输入:\n");
|
|
|
scanf("%c",&c);
|
|
|
getchar();
|
|
|
if(c=='y'||c=='Y')
|
|
|
{
|
|
|
system("cls");
|
|
|
menu();
|
|
|
}
|
|
|
if(c=='n'||c=='N')
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int menu_select()//菜单选择
|
|
|
{int a;
|
|
|
printf("\n");
|
|
|
printf("\t*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
|
|
|
printf("\t*-0. 添加学生信息 -*\n");
|
|
|
printf("\t*-1. 修改学生信息 -*\n");
|
|
|
printf("\t*-2. 显示学生信息 -*\n");
|
|
|
printf("\t*-3. 查询学生信息 -*\n");
|
|
|
printf("\t*-4. 学生信息排序 -*\n");
|
|
|
printf("\t*-5. 最高和最低分 -*\n");
|
|
|
printf("\t*-6. 平均分 -*\n");
|
|
|
printf("\t*-7. 及格率 -*\n");
|
|
|
printf("\t*-8. 学生成绩分段 -*\n");
|
|
|
printf("\t*-9. 结束运行 -*\n");
|
|
|
printf("\t*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
|
|
|
printf("\n\t请输入功能选择对应的数据, 请选0~9:\n");
|
|
|
scanf("%d",&a);
|
|
|
getchar();//接收回车符
|
|
|
while(!(a>=0&&a<=9))
|
|
|
{
|
|
|
printf("你的输入怕是有点问题哦,麻烦再输入一次");
|
|
|
scanf("%d",&a);
|
|
|
getchar();
|
|
|
}
|
|
|
return a;
|
|
|
}
|
|
|
|
|
|
int xg() //修改
|
|
|
{
|
|
|
FILE *fp1;
|
|
|
char st[30];
|
|
|
int num,k,x,id;
|
|
|
float nu;
|
|
|
system("cls");
|
|
|
wenjiandiaochu();
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
return 0;
|
|
|
}
|
|
|
fscanf(fp1,"%d",&k);
|
|
|
fclose(fp1);
|
|
|
printf("学号修改请按1,姓名修改请按2,莫要选错了:\n");
|
|
|
scanf("%d",&x);
|
|
|
while(x!=1&&x!=2)
|
|
|
{
|
|
|
printf("你的输入怕是有毛病,现在请重新输入:\n");
|
|
|
scanf("%d",&x);
|
|
|
}
|
|
|
if(x==1)
|
|
|
{
|
|
|
printf("现在输入修改成绩人的学号:\n");
|
|
|
scanf("%d",&num);
|
|
|
for(int i=0;i<k;i++)
|
|
|
{
|
|
|
if(num==s[i].xh)
|
|
|
{
|
|
|
printf("请输入修改后的学号:\n");
|
|
|
scanf("%d",&id);
|
|
|
s[i].xh=id;
|
|
|
printf("请输入修改后的姓名:\n");
|
|
|
scanf("%s",st);
|
|
|
strcpy(s[i].name,st);
|
|
|
printf("请输入修改后的成绩:\n");
|
|
|
scanf("%f",&nu);
|
|
|
getchar();
|
|
|
s[i].score=nu;
|
|
|
fp=fopen("student.txt","w+");
|
|
|
for(i=0;i<k;i++)
|
|
|
fprintf(fp,"%d %s %.1f\n",s[i].xh,s[i].name,s[i].score);
|
|
|
fclose(fp);
|
|
|
printf("搞定\n");
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
printf("冒油找到这个学生的信息\n");
|
|
|
return 0;
|
|
|
}
|
|
|
if(x==2)
|
|
|
{
|
|
|
printf("现在输入修改成绩人的姓名:\n");
|
|
|
scanf("%s",st);
|
|
|
for(int i=0;i<k;i++)
|
|
|
{
|
|
|
if(strcmp(s[i].name,st)==0)
|
|
|
{
|
|
|
char str[30];
|
|
|
printf("请输入修改后的学号:\n");
|
|
|
scanf("%d",&id);
|
|
|
s[i].xh=id;
|
|
|
printf("请输入修改后的姓名:\n");
|
|
|
scanf("%s",st);
|
|
|
strcpy(s[i].name,st);
|
|
|
printf("请输入修改后的成绩:\n");
|
|
|
scanf("%f",&nu);
|
|
|
getchar();
|
|
|
for(i=0;i<k;i++)
|
|
|
fprintf(fp,"%d %s %.1f\n",s[i].xh,s[i].name,s[i].score);
|
|
|
fclose(fp);
|
|
|
printf("搞定\n");
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
printf("冒油找到这个学生的信息\n");
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void cx()//查询
|
|
|
{
|
|
|
FILE *fp1;
|
|
|
char st[30];
|
|
|
int x,num,k=0;
|
|
|
wenjiandiaochu();
|
|
|
system("cls");
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%d",&k);
|
|
|
fclose(fp1);
|
|
|
|
|
|
printf("学号查询请按1,姓名查询请按2。莫要选错了:\n");
|
|
|
scanf("%d",&x);
|
|
|
while(x!=1&&x!=2)
|
|
|
{
|
|
|
printf("你的输入怕是有毛病,现在请重新输入:\n");
|
|
|
scanf("%d",&x);
|
|
|
}
|
|
|
if(x==1)
|
|
|
{
|
|
|
printf("现在输入需要查询的学号:\n");
|
|
|
scanf("%d",&num);
|
|
|
for(int i=0;i<k;i++)
|
|
|
if(num==s[i].xh)
|
|
|
{
|
|
|
printf("学号:%d\n姓名:%s\n成绩:%.1f\n",s[i].xh,s[i].name,s[i].score);
|
|
|
return;
|
|
|
}
|
|
|
printf("冒得这个学生的信息\n");
|
|
|
return;
|
|
|
}
|
|
|
if(x==2)
|
|
|
{printf("现在输入需要查询的姓名:\n");
|
|
|
scanf("%s",st);
|
|
|
for(int i=0;i<k;i++)
|
|
|
if(strcmp(s[i].name,st)==0)
|
|
|
{
|
|
|
printf("学号:%d\n姓名:%s\n成绩:%.1f\n",s[i].xh,s[i].name,s[i].score);
|
|
|
return;
|
|
|
}
|
|
|
printf("冒得这个学生的信息\n");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void tj()//添加
|
|
|
{ FILE *fp1;
|
|
|
system("cls");
|
|
|
int i,j,c;
|
|
|
int a=1;
|
|
|
if((fp=fopen("student.txt","a"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
return;
|
|
|
}
|
|
|
for(i=0;a!=0;)
|
|
|
{
|
|
|
int d,x;
|
|
|
float z;
|
|
|
char st[30];
|
|
|
printf("现在输入你要添加学生的学号:\n");
|
|
|
scanf("%d",&x);
|
|
|
getchar();
|
|
|
printf("现在输入你要添加学生的姓名:\n");
|
|
|
gets(st);
|
|
|
printf("现在输入你要添加学生的成绩:\n");
|
|
|
scanf("%f",&z);
|
|
|
getchar();
|
|
|
fprintf(fp,"%d %s %.1f\n",x,st,z);
|
|
|
printf("请以0作为输入信息结束!,输入1继续\n");
|
|
|
scanf("%d",&d);
|
|
|
getchar();//接受回车
|
|
|
a=d;
|
|
|
while(a!=1&&a!=0)
|
|
|
{
|
|
|
printf("你的输入怕是有毛病,现在请重新输入:\n");
|
|
|
scanf("%d",&a);
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)//修改学生人数.txt文件
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%d",&j);
|
|
|
fclose(fp1);
|
|
|
rewind(fp1);
|
|
|
if((fp1=fopen("学生人数.txt","w"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
c=j+i;
|
|
|
fprintf(fp1,"%d",c);
|
|
|
fclose(fp1);
|
|
|
}
|
|
|
|
|
|
void xs()//显示
|
|
|
{ system("cls");
|
|
|
int ch;
|
|
|
if((fp=fopen("student.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件打开失败\n");
|
|
|
exit(0);
|
|
|
}
|
|
|
printf("\t\t\t全部的学生信息:\n");
|
|
|
printf("\t****************\n");
|
|
|
printf("\t*学号 name 成绩*\n");
|
|
|
printf("\t****************\n");
|
|
|
while(!feof(fp))
|
|
|
{
|
|
|
ch=fgetc(fp);
|
|
|
putchar(ch);
|
|
|
}
|
|
|
fclose(fp);
|
|
|
|
|
|
}
|
|
|
|
|
|
void pm()//排名
|
|
|
{
|
|
|
wenjiandiaochu();
|
|
|
int i=0,k,m=0,a;
|
|
|
char c;
|
|
|
float average,pass,sum=0;
|
|
|
struct stu t;
|
|
|
FILE *fp1;
|
|
|
system("cls");
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%d",&k);
|
|
|
fclose(fp1);
|
|
|
for(i=0;i<k;i++)
|
|
|
{
|
|
|
|
|
|
for(j=i+1;j<k+1;j++)
|
|
|
{
|
|
|
|
|
|
if(s[i].score<s[j].score)
|
|
|
{
|
|
|
t=s[i];
|
|
|
s[i]=s[j];
|
|
|
s[j]=t;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for(i=0;i<k;i++)
|
|
|
{ /* sum=sum+s[i].score;
|
|
|
if(s[i].score>=60)
|
|
|
m++; */
|
|
|
printf("\t\t\t第%d名:%d %-4s %.1f\n",i+1,s[i].xh,s[i].name,s[i].score);
|
|
|
}
|
|
|
printf("是否要将排序后的数据保存,是请按1,否请按0:\n");
|
|
|
scanf("%d",&a);
|
|
|
c=getchar();//接收回车
|
|
|
while(a!=1&&a!=0)
|
|
|
{
|
|
|
printf("你的输入怕是有毛病,现在请重新输入:\n");
|
|
|
scanf("%d",&a);
|
|
|
}
|
|
|
if(a==1)
|
|
|
{
|
|
|
if((fp=fopen("student.txt","w+"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
for(int l=0;l<k;l++)
|
|
|
{
|
|
|
fprintf(fp,"%d %s %.1f",s[l].xh,s[l].name,s[l].score);
|
|
|
fprintf(fp,"\n");
|
|
|
}
|
|
|
printf("搞定!\n");
|
|
|
fclose(fp);
|
|
|
if(a==0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
/*average=sum/i;
|
|
|
pass=m/i;
|
|
|
printf("这门课程学生的最高成绩是:%d",s[0]);
|
|
|
printf("这门课程学生的最低成绩是:%d",s[i]);
|
|
|
printf("这门课程学生的平均成绩是:%d",average);
|
|
|
printf("这门课程学生的及格率是:%d",pass);*/
|
|
|
}
|
|
|
|
|
|
void fd()//成绩分段
|
|
|
{ int k;
|
|
|
FILE *fp1;
|
|
|
system("cls");
|
|
|
wenjiandiaochu();
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%d",&k);
|
|
|
fclose(fp1);
|
|
|
printf("\t\t\t 90分以上学生的信息!\n");
|
|
|
printf("\t\t\t学号 姓名 成绩:\n");
|
|
|
for(i=0;i<k;i++)
|
|
|
if(s[i].score>=90)
|
|
|
printf("\t\t\t%d %s %.1f%ld\n",s[i].xh,s[i].name,s[i].score);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 80到89分学生的信息!\n");
|
|
|
printf("\t\t\t学号 姓名 成绩:\n");
|
|
|
for(i=0;i<k;i++)
|
|
|
if(s[i].score<90&&s[i].score>=80)
|
|
|
printf("\t\t\t%d %s %.1f%ld\n",s[i].xh,s[i].name,s[i].score);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 60到79分学生的信息!\n");
|
|
|
printf("\t\t\t学号 姓名 成绩:\n");
|
|
|
for(i=0;i<k;i++)
|
|
|
if(s[i].score>=60&&s[i].score<80)
|
|
|
printf("\t\t\t%d %s %.1f%ld\n",s[i].xh,s[i].name,s[i].score);
|
|
|
printf("\n\n");
|
|
|
printf("\t\t\t 60分以下学生的信息!\n");
|
|
|
printf("\t\t\t学号 姓名 成绩:\n");
|
|
|
for(i=0;i<k;i++)
|
|
|
if(s[i].score<60)
|
|
|
printf("\t\t\t%d %s %.1f%ld\n",s[i].xh,s[i].name,s[i].score);
|
|
|
printf("\n\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
int wenjiandiaochu()//数据提取
|
|
|
{
|
|
|
int i;
|
|
|
FILE *fp;
|
|
|
if((fp=fopen("student.txt","a+"))==NULL)
|
|
|
{
|
|
|
printf("这个文件打开出了点问题\n");
|
|
|
exit(0);
|
|
|
}
|
|
|
for(i=0;!feof(fp);)
|
|
|
{
|
|
|
fscanf(fp,"%d%s%f",&s[i].xh,&s[i].name,&s[i].score);
|
|
|
i++;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
float fm()//最高分最低分
|
|
|
{
|
|
|
FILE *fp1;
|
|
|
int k;
|
|
|
float max,min,sum=0;
|
|
|
wenjiandiaochu();
|
|
|
system("cls");
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%d",&k);
|
|
|
fclose(fp1);
|
|
|
max=s[0].score;
|
|
|
min=s[0].score;
|
|
|
for(int i=1;i<k;i++)
|
|
|
{
|
|
|
if(s[i].score>max)
|
|
|
max=s[i].score;
|
|
|
if(s[i].score<min)
|
|
|
min=s[i].score;
|
|
|
}
|
|
|
printf("当前最高分:%.1f\n当前最低分:%.1f\n",max,min);
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
int average()//平均分
|
|
|
{
|
|
|
FILE *fp1;
|
|
|
system("cls");
|
|
|
wenjiandiaochu();
|
|
|
float k,c,sum=0;
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%f",&k);
|
|
|
fclose(fp1);
|
|
|
for(int i=1;i<k;i++)
|
|
|
{
|
|
|
sum=sum+s[i].score;
|
|
|
}
|
|
|
c=sum/k;
|
|
|
printf("当前学生C语言成绩的平均分为:%.2f\n",c);
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
int pass()//及格率
|
|
|
{
|
|
|
FILE *fp1;
|
|
|
system("cls");
|
|
|
wenjiandiaochu();
|
|
|
float k,c,p=0;
|
|
|
int i;
|
|
|
if((fp1=fopen("学生人数.txt","r"))==NULL)
|
|
|
{
|
|
|
printf("文件冇得办法打开");
|
|
|
exit(0);
|
|
|
}
|
|
|
fscanf(fp1,"%f",&k);
|
|
|
fclose(fp1);
|
|
|
for(i=0;i<k;i++)
|
|
|
{
|
|
|
if(s[i].score>=60)
|
|
|
p++;
|
|
|
}
|
|
|
c=p/k;
|
|
|
printf("当前学生C语言成绩的及格率为:%.2f\n",c);
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
int mima()//密码设置
|
|
|
{
|
|
|
char m[10],c;
|
|
|
int i;
|
|
|
printf("\n\n\n\n\t\t\t\t请输入8位数字管理员密码:\n");
|
|
|
for(i=0;i<8;i++)
|
|
|
{
|
|
|
m[i]=getch();
|
|
|
printf("$");
|
|
|
}
|
|
|
c=getchar();//接收回车符
|
|
|
m[i]='\0';//用空格做结束标记,使后面的i+n作废
|
|
|
printf("\n");
|
|
|
if(strcmp(m,"14789632")==0)
|
|
|
return 0;
|
|
|
if(strcmp(m,"14789632")!=0)
|
|
|
{
|
|
|
printf("密码不对呀!你怕四记错了哦!响一哈再输入一次:\n");
|
|
|
for(i=0;i<8;i++)
|
|
|
{
|
|
|
m[i]=getch();
|
|
|
printf("$");
|
|
|
}
|
|
|
c=getchar();//接收回车符
|
|
|
m[i]='\0';//用空格做结束标记,使后面的i+n作废
|
|
|
printf("\n");
|
|
|
if(strcmp(m,"14789632")==0)
|
|
|
return 0;
|
|
|
else
|
|
|
{
|
|
|
printf("密码错误,系统退出\n");
|
|
|
return 1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|