first commit

master
fengzaiyao 6 years ago
commit bec14aeaa6

@ -0,0 +1,441 @@
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"math.h"
struct student
{
char xh[12];
char name[20];
char sex[20];
int yw;
int sx;
int yy;
int zf;
};
void menu()
{
printf("\n\n\n");
printf("\t\t|----------------学生管理系统---------------|\n");
printf("\t\t|\t 0 退出 |\n");
printf("\t\t|\t 1 学生信息录入 |\n");
printf("\t\t|\t 2 学生成绩查询 |\n");
printf("\t\t|\t 3 显示全部学生成绩 |\n");
printf("\t\t|\t 4 查看各个分数段成绩的人数 |\n");
printf("\t\t|\t 5 学生各科成绩分析 |\n");
printf("\t\t|\t 6 删除指定学生信息 |\n");
printf("\t\t|\t 7 修改指定学生信息 |\n");
printf("\t\t|-------------------------------------------|\n");
printf("\n");
}
void chenjifenxi();
void add();
void search();
void printall();
void score_section();
void del();
void modify();
int main()
{
menu();
int n;
printf(" 请输入数字0-7: ");
scanf("%d",&n);
while(n)
{
switch(n)
{
case 0:break;
case 1:add();break;
case 2:search();break;
case 3:printall();break;
case 4:score_section();break;
case 5:chenjifenxi();break;
case 6:del();break;
case 7:modify();break;
default:printf("输入错误");
}
menu();
printf("如果想继续查询请按0-7,否者按0退出");
scanf("%d",&n);
}
return 0;
}
void add()
{
struct student boy[20];
FILE *fp;
int a=1;
int i=0,flag=0;
fp=fopen("student.txt","a+");
if(fp==NULL)
{
printf("打开失败");
}
while(a==1)
{
printf("请输入学号");
scanf("%s",boy[i].xh);
printf("请输入姓名");
scanf("%s",boy[i].name);
printf("请输入性别");
scanf("%s",boy[i].sex);
printf("请输入语文");
scanf("%d",&boy[i].yw);
printf("请输入数学");
scanf("%d",&boy[i].sx);
printf("请输入英语");
scanf("%d",&boy[i].yy);
boy[i].zf=boy[i].yw+boy[i].yy+boy[i].sx;
fprintf(fp,"%s %s %s %d %d %d %d",boy[i].xh,boy[i].name,boy[i].sex,boy[i].yw,boy[i].sx,boy[i].yy,boy[i].zf);
fprintf(fp,"\n");
i++;
printf("如果想继续输入请输入1否则按任意键 :");
scanf("%d",&a);
if(a==0)
{
break;
}
}
fclose(fp);
}
void search()
{
FILE *fp;
char ch[20];
int i=0,flag=0;
struct student boy[50];
fp=fopen("student.txt","ab+");
if(fp==NULL)
{
printf("打开失败");
}
printf("请输入你想要查询的学号或者姓名: ");
scanf("%s",&ch);
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
}
for(int j=0;j<50;j++)
{
if((strcmp(ch,boy[j].xh)==0)||(strcmp(ch,boy[j].name)==0))
{
printf("学号: %s \n名字: %s \n性别: %s \n语文: %d \n数学: %d \n英语: %d \n总分: %d",boy[j].xh,boy[j].name,boy[j].sex,boy[j].yw,boy[j].sx,boy[j].yy,boy[j].zf);
flag=1;
}
}
if(flag==0)
{
printf("查无此人");
}
fclose(fp);
}
void printall()
{
FILE *fp;
int i=0,k=0,j,a,b,flag;
struct student boy[50];
struct student gilr;
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("打开失败");
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
k++;
}
printf("想按照总分排序输出请按1\n想按照语文成绩排序请按2\n想按照数学成绩排序请按3\n想按照英语成绩排序请按4\n");
scanf("%d",&flag);
if(flag==1)
{
for(a=0;a<k-1;a++)
{
for(b=a+1;b<k-1;b++)
{
if(boy[a].zf<boy[b].zf)
{
gilr=boy[a];
boy[a]=boy[b];
boy[b]=gilr;
}
}
}
}else if(flag==2){
for(a=0;a<k-1;a++)
{
for(b=a+1;b<k-1;b++)
{
if(boy[a].yw<boy[b].yw)
{
gilr=boy[a];
boy[a]=boy[b];
boy[b]=gilr;
}
}
}
}else if(flag==3){
for(a=0;a<k-1;a++)
{
for(b=a+1;b<k-1;b++)
{
if(boy[a].sx<boy[b].sx)
{
gilr=boy[a];
boy[a]=boy[b];
boy[b]=gilr;
}
}
}
}else if(flag==4){
for(a=0;a<k-1;a++)
{
for(b=a+1;b<k-1;b++)
{
if(boy[a].yy<boy[b].yy)
{
gilr=boy[a];
boy[a]=boy[b];
boy[b]=gilr;
}
}
}
}else{
printf("输入数字有误,顺序将打乱输出");
}
for(j=0;j<k-1;j++)
{
printf("名字: %s 语文: %d 数学: %d 英语: %d 总分: %d",boy[j].name,boy[j].yw,boy[j].sx,boy[j].yy,boy[j].zf);
printf("\n");
}
fclose(fp);
}
void score_section()
{
FILE *fp;
struct student boy[50];
int i=0,k=0;
int a=0,b=0,c=0,d=0,e=0,f=0;
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("打开失败");
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
k++;
}
for(int j=0;j<k-1;j++)
{
if(boy[j].yw<60)
{
a++;
}
if(boy[j].yw>=60){
b++;
}
if(boy[j].sx<60){
c++;
}
if(boy[j].sx>=60){
d++;
}
if(boy[j].yy<60){
e++;
}if(boy[j].yy>=60){
f++;
}
}
printf("语文低于60分有%d人\n语文大于60分有%d人\n数学低于60分有%d人\n数学大于60分有%d人\n英语低于60分有%d人\n英语大于60分有%d人\n",a,b,c,d,e,f);
fclose(fp);
}
void chenjifenxi()
{
FILE *fp;
struct student boy[50];
int i=0,k=0,ywmax,ywmin,sxmax,sxmin,yymax,yymin,ywavg,sxavg,yyavg;
double ywsum=0,sxsum=0,yysum=0,ywpass=0,sxpass=0,yypass=0;
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("打开失败");
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
k++;
}
ywmax=boy[0].yw;
ywmin=boy[1].yw;
sxmax=boy[0].sx;
sxmin=boy[1].sx;
yymax=boy[0].yy;
yymin=boy[1].yy;
for(int j=0;j<k-1;j++)
{
if(boy[j].yw>ywmax)
{
ywmax=boy[j].yw;
}
if(boy[j].yw<ywmin)
{
ywmin=boy[j].yw;
}
if(boy[j].sx>sxmax)
{
sxmax=boy[j].sx;
}
if(boy[j].sx<sxmin)
{
sxmin=boy[j].sx;
}
if(boy[j].yy>yymax)
{
yymax=boy[j].yy;
}
if(boy[j].yy<yymin)
{
yymin=boy[j].yy;
}
}
for(int m=0;m<k-1;m++)
{
ywsum+=boy[m].yw;
sxsum+=boy[m].sx;
yysum+=boy[m].yy;
}
for(int a=0;a<k-1;a++)
{
if(boy[a].yw>=60)
{
ywpass++;
}
if(boy[a].sx>=60)
{
sxpass++;
}
if(boy[a].yy>=60)
{
yypass++;
}
}
printf("语文最高分:%d 语文最低分:%d 语文平均分:%.2f\n数学最高分:%d 数学最低分:%d 数学平均分:%.2f\n英语最高分:%d 英语最低分:%ld 英语平均分:%.2f\n",ywmax,ywmin,ywsum/(k-1),sxmax,sxmin,sxsum/(k-1),yymax,yymin,yysum/(k-1));
printf("语文及格率 %.2f%% \n数学及格率 %.2f%% \n英语及格率 %.2f%%\n",(ywpass/(k-1))*100,(sxpass/(k-1))*100,(yypass/(k-1))*100);
printf("语文总分:%.0f 数学总分:%.0f 英语总分:%.0f",ywsum,sxsum,yysum);
fclose(fp);
}
void del()
{
FILE *fp;
int i=0,k=0,z,x,j,flag=0;
char s[12];
struct student boy[50];
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("打开失败");
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
k++;
}
fclose(fp);
printf("请输入想要删除的学号");
scanf("%s",s);
for(j=0;j<k;j++)
{
if(strcmp(s,boy[j].xh)==0)
{
z=j;
flag=1;
}
}
if(flag==1)
{
for(x=z;x<k-1;x++)
{
boy[x]=boy[x+1];
}
k=k-1;//将总个数减少一个
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("打开失败");
}
for(j=0;j<k-1;j++)
{
fprintf(fp,"%s %s %s %d %d %d %d",boy[j].xh,boy[j].name,boy[j].sex,boy[j].yw,boy[j].sx,boy[j].yy,boy[j].zf);
fprintf(fp,"\n");
}
fclose(fp);
}else{
printf("没有找到要删除的学生信息");
}
}
void modify()
{
FILE *fp;
int i=0,k=0,j,z,flag=0;
char s[12];
struct student boy[50];
fp=fopen("student.txt","r");
if(fp==NULL)
{
printf("打开失败");
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d",boy[i].xh,boy[i].name,boy[i].sex,&boy[i].yw,&boy[i].sx,&boy[i].yy,&boy[i].zf);
i++;
k++;
}
fclose(fp);
printf("请输入你想要修改学生信息的学号: ");
scanf("%s",s);
for(j=0;j<k-1;j++)
{
if(strcmp(s,boy[j].xh)==0)
{
z=j;
flag=1;
}
}
if(flag==1)
{
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("打开失败");
}
printf("请重新输入学号");
scanf("%s",boy[z].xh);
printf("请重新输入姓名");
scanf("%s",boy[z].name);
printf("请重新输入性别");
scanf("%s",boy[z].sex);
printf("请重新输入语文成绩");
scanf("%d",&boy[z].yw);
printf("请重新输入数学成绩");
scanf("%d",&boy[z].sx);
printf("请重新输入英语成绩");
scanf("%d",&boy[z].yy);
boy[z].zf=boy[z].sx+boy[z].yw+boy[z].yy;
for(j=0;j<k-1;j++)
{
fprintf(fp,"%s %s %s %d %d %d %d",boy[j].xh,boy[j].name,boy[j].sex,boy[j].yw,boy[j].sx,boy[j].yy,boy[j].zf);
fprintf(fp,"\n");
}
fclose(fp);
}else{
printf("我也莫得办法,我找不到要修改的学生信息");
}
}

Binary file not shown.
Loading…
Cancel
Save