You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
6.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i,j,k,y;
FILE *fp;
struct stu
{
int no;
char name[30];
float cscore;
long a;
};struct stu s[100];
int fun()
{
int n,i;
system("cls");
printf("\n\n\t\t\t\t 成绩记录簿");
printf("\n\n\t\t\t");
for(i=0;i<33;i++)
printf("*");
printf("\n");
printf("\t\t\t *********菜单********\n");
printf("\t\t\t* 1、创建学生的信息 \t*\n");
printf("\t\t\t* 2、输出所有学生的信息 \t*\n");
printf("\t\t\t* 3、修改成绩 \t*\n");
printf("\t\t\t* 4、查询 \t*\n");
printf("\t\t\t* 5、显示成绩分段的学生信息 \t*\n");
printf("\t\t\t* 6、显示及格率、平均分、最高分和最低分 \t*\n");
printf("\t\t\t* 7、学生成绩排名 \t*\n");
printf("\t\t\t* 8、退出成绩记录簿 \t*\n");
printf("\t\t\t");
for(i=0;i<33;i++)
printf("*");
printf("\n\n");
printf("\n\t\t\t 请输入选项:");
scanf("%d",&n);
return n;
}
void input()
{
system("cls");
i=0;
fp=fopen("out.dat","w");
printf("请以0作为输入学生学号信息的结束\n");
do
{
printf("输入学生的学号:");
scanf("%d",&s[i].no);
printf("输入学生的姓名:");
scanf("%s",s[i].name);
printf("输入学生的C语言成绩");
scanf("%f",&s[i].cscore);
printf("输入添加成绩的时间:");
scanf("%ld",&s[i].a);
if(s[i].no!=0)
fprintf(fp,"%d %-4s %.1f %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
}while(s[i].no!=0);
fclose(fp);
}
void output()
{
if((fp=fopen("out.dat","r"))==NULL)
{
printf("Cannot open the file!\n");
}
printf("\t\t\t全部的学生信息:\n");
k=0;
while(fscanf(fp,"%d%s%f%ld",&s[k].no,s[k].name,&s[k].cscore,&s[k].a)!=EOF)
{
printf("\t\t\t%d\t%s\t%.lf\t%ld\n",s[k].no,s[k].name,s[k].cscore,s[k].a);
k++;
}
fclose(fp);
}
void modify()
{
char st[30];
int x,num;
float nu;
long h;
k=0;
system("cls");
if((fp=fopen("out.dat","r"))==NULL)
{
printf("Cannot open the file!\n");
return;
}
while(fscanf(fp,"%d%s%f%ld",&s[k].no,s[k].name,&s[k].cscore,&s[k].a)!=EOF)
{
k++;
}
fclose(fp);
printf("输入1表示用学号修改输入2表示用姓名修改请选择\n");
scanf("%d",&x);
if(x==1)
{
printf("请输入修改成绩人的学号;");scanf("%d",&num);
for(i=0;i<k;i++)
if(num==s[i].no)
{
printf("请输入修改的成绩;\n");
scanf("%f",&nu);
s[i].cscore=nu;
printf("请输入修改的时间;\n");
scanf("%ld",&h);
s[i].a=h;
fp=fopen("out.dat","w");
for(i=0;i<k;i++)
fprintf(fp,"%d %s %.lf %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
fclose(fp);
printf("修改成功\n");
return;
}
printf("没有找到该生的信息!\n");
return;
}
if(x==2)
{
printf("请输入修改成绩人的姓名;");
scanf("%s",st);
for(i=0;i<k;i++)
if(strcmp(s[i].name,st)==0)
{
printf("请输入修改成绩的时间;\n");
scanf("%ld",&h);
s[i].a=h;
fp=fopen("out.dat","w");
for(i=0;i<k;i++)
fprintf(fp,"%d %s %.lf %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
fclose(fp);
printf("修改成功\n");
return;
}
printf("没有找到该生的信息!\n");
return;
}
}
void lookat()
{
char st[30];
int x,num;
k=0;
system("cls");
if((fp=fopen("out.dat","r"))==NULL)
{
printf("Cannot open the file!\n");
return;
}
while(fscanf(fp,"%d%s%f%ld",&s[k].no,s[k].name,&s[k].cscore,&s[k].a)!=EOF)
{
k++;
}
printf("输入1表示用学号查询输入2表示用姓名查询请选择\n");
scanf("%d",&x);
if(x==1)
{
printf("请输入查询的学号:");
scanf("%d",&num);
for(i=0;i<k;i++)
if(num==s[i].no)
{
printf("%d %s %.1f%ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
return;
}
printf("对不起,找不到该生!\n");
return;
}
if(x==2)
{
printf("请输入查询的姓名:");
scanf("%s",st);
for(i=0;i<k;i++)
if(strcmp(s[i].name,st)==0)
{
printf("%d % s %.1f %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
return;
}
printf("对不起,找不到该生!\n");
}
}
void subsection()
{
system("cls");
k=0;
if((fp=fopen("out.dat","r"))==NULL)
{
printf("Cannot open the file!\n");
}
while(fscanf(fp,"%d%s%f%ld",&s[k].no,s[k].name,&s[k].cscore,&s[k].a)!=EOF)
{
k++;
}
printf("\t\t\t 90分以上学生的信息\n");
for(i=0;i<k;i++)
if(s[i].cscore>=90)
printf("\t\t\t%d %s %.1f %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
printf("\n\n");
printf("\t\t\t 80到89分学生的信息\n");
for(i=0;i<k;i++)
if(s[i].cscore<90&&s[i].cscore>=80)
printf("\t\t\t%d %s %.1f %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
printf("\n\n");
printf("\t\t\t 60到79分学生的信息\n");
for(i=0;i<k;i++)
if(s[i].cscore>=60&&s[i].cscore<80)
printf("\t\t\t%d %s %.1f %ld\n",s[i].no,s[i].name,s[i].cscore,s[i].a);
printf("\n\n");
}
void demonstrate()
{
int max,min,score;
double avg=0;
scanf("%d",&score);
max=min=score;
avg+=score;
for(i=0; i<29; i++)
{
scanf("%d",&score);
if(score>max) max=score;
if(score<min) min=score;
avg+=score;
}
avg=avg/30;
printf("最高分max=%d,最低分min=%d,平均分avg=%lf\n",max,min,avg);
}
void rank()
{
struct stu t;
k=0;
system("cls");
if((fp=fopen("out.dat","r"))==NULL)
{
printf("Cannot open the file!\n");
}
while(fscanf(fp,"%d%s%f%ld",&s[k].no,s[k].name,&s[k].cscore,&s[k].a)!=EOF)
{
k++;
}
for(i=0;i<k;i++)
for(j=i+1;j<k+1;j++)
if(s[i].cscore<s[j].cscore)
{t=s[i];s[i]=s[j];s[j]=t;}
for(i=0;i<k;i++)
printf("\t\t\t 第%d名%d %-4s %.1f %ld\n",i+1,s[i].no,s[i].name,s[i].cscore,s[i].a);
}
void choose(int n)
{
system("cls");
switch(n)
{
case 1:input();
printf("\n\n\n\n\t\t\t是否返回输入1表示返回输入2表示退出!\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 2:output();
printf("\n\n\n\n\t\t\t是否返回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 3:modify();
printf("\n\n\n\n\t\t\t是否返回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 4:lookat();
printf("\n\n\n\n\t\t\t是否返回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 5:subsection();
printf("\n\n\n\n\t\t\t是否返回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 6:demonstrate();
printf("\n\n\n\n\t\t\t是否赶回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 7:rank();
printf("\n\n\n\n\t\t\t是否赶回输入1表示返回输入2表示退出\n");
scanf("%d",&y);
if(y==1)
choose(fun());break;
case 8:exit(0);break;
default:printf("\n\n\t\t\t输入没有的选项,请重新输入!\n");
choose(fun());
}
}
int main(void)
{
int n;
system("cls");
n=fun();
choose(n);
}