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.
252 lines
5.5 KiB
252 lines
5.5 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
int i,j,k,y;
|
|
FILE *fp;
|
|
struct stu {
|
|
int num;
|
|
char name[30];
|
|
double cscore;
|
|
};
|
|
struct stu s[100];
|
|
|
|
int fun() { // 目录函数
|
|
int n;
|
|
system("cls");
|
|
printf("\n\n\t\t\t\t欢迎使用成绩记录薄 ");
|
|
printf("\n\n\t\t\t");
|
|
printf("************ 菜 单 *************\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\t[8]在原文件基础上添加学生信息\n");
|
|
printf("\t\t\t[9]退出成绩记录薄\n");
|
|
printf("\t\t\t");
|
|
for(i=0; i<32; i++)
|
|
printf("-");
|
|
printf("\n\n");
|
|
printf("\n\t\t\t请输入选项:");
|
|
scanf("%d",&n);
|
|
return n;
|
|
}
|
|
|
|
void input() {
|
|
system("cls");
|
|
i=0;
|
|
fp=fopen("stuinfo","w");
|
|
printf("*结束请在学号、姓名、成绩栏输入 0*\n");
|
|
do {
|
|
printf("输入学生的学号:");
|
|
scanf("%d",&s[i].num);
|
|
printf("输入学生的姓名:");
|
|
scanf("%s",s[i].name);
|
|
printf("输入学生的 C 语言成绩:");
|
|
scanf("%lf",&s[i].cscore);
|
|
if(s[i].num!=0)
|
|
fprintf(fp,"%d%-4s%.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
} while(s[i].num!=0);
|
|
fclose(fp);
|
|
}
|
|
|
|
void output() {
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
}
|
|
printf("\t\t\t 全部的学生信息:\n");
|
|
k=0;
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=EOF) {
|
|
printf("\t\t\t%d\t%s\t%.1lf\n",s[k].num,s[k].name,s[k].cscore);
|
|
k++;
|
|
}
|
|
fclose(fp);
|
|
}
|
|
|
|
void add() {
|
|
system("cls");
|
|
i=0;
|
|
fp=fopen("stuinfo","a");
|
|
printf("*结束请在学号、姓名、成绩栏输入 0*\n");
|
|
do {
|
|
printf("输入学生的学号:");
|
|
scanf("%d",&s[i].num);
|
|
printf("输入学生的姓名:");
|
|
scanf("%s",s[i].name);
|
|
printf("输入学生的 C 语言成绩:");
|
|
scanf("%lf",&s[i].cscore);
|
|
if(s[i].num!=0)
|
|
fprintf(fp,"%d%-4s%.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
} while(s[i].num!=0);
|
|
fclose(fp);
|
|
}
|
|
|
|
void modify() { //修改
|
|
char st[30];
|
|
int x,num;
|
|
double nu;
|
|
long h;
|
|
k=0;
|
|
system("cls");
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
return;
|
|
}
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=EOF) {
|
|
k++;
|
|
}
|
|
fclose(fp);
|
|
printf("[1]用学号查询\n[2]用姓名查询\n请选择:\n");
|
|
scanf("%d",&x);
|
|
if(x==1) {
|
|
printf("请输入学号:");
|
|
scanf("%d",&num);
|
|
for(i=0; i<k; i++)
|
|
if(num==s[i].num) {
|
|
printf("请输入修改的成绩:\n");
|
|
scanf("%lf",&nu);
|
|
s[i].cscore=nu;
|
|
fp=fopen("stuinfo","w");
|
|
for(i=0; i<k; i++)
|
|
fprintf(fp,"%d%-4s%.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
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("%lf",&nu);
|
|
s[i].cscore=nu;
|
|
fp=fopen("stuinfo","w");
|
|
for(i=0; i<k; i++)
|
|
fprintf(fp,"%d%-4s%.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
fclose(fp);
|
|
printf(" 修改成功 \n");
|
|
return;
|
|
}
|
|
printf(" 没有找到该学生!\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
void lookat() { //查询
|
|
char st[30];
|
|
int x,num;
|
|
k=0;
|
|
system("cls");
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
return;
|
|
}
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=EOF) {
|
|
k++;
|
|
}
|
|
printf("[1]用学号查询\n[2]用姓名查询\n请选择:\n");
|
|
scanf("%d",&x);
|
|
if(x==1) {
|
|
printf("请输入学号:");
|
|
scanf("%d",&num);
|
|
for(i=0; i<k; i++)
|
|
if(num==s[i].num) {
|
|
printf("%d %s %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
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 %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
return;
|
|
}
|
|
printf("对不起,没有找到该学生\n");
|
|
}
|
|
}
|
|
|
|
void subsection() { //分段
|
|
system("cls");
|
|
k=0;
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
}
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=EOF) {
|
|
k++;
|
|
}
|
|
printf("\t\t90 分以上学生的信息\n");
|
|
for(i=0; i<k; i++)
|
|
if(s[i].cscore>=90)
|
|
printf("\t\t\t%d %s %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
printf("\n\n");
|
|
printf("\t\t80 到 89 分学生的信息\n");
|
|
for(i=0; i<k; i++)
|
|
if(s[i].cscore<90&&s[i].cscore>=80)
|
|
printf("\t\t\t%d %s %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
printf("\n\n");
|
|
printf("\t\t60 到 79 分学生的信息\n");
|
|
for(i=0; i<k; i++)
|
|
if(s[i].cscore>=60&&s[i].cscore<80)
|
|
printf("\t\t\t%d %s %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
printf("\n\n");
|
|
printf("\t\t60 分以下学生的信息\n");
|
|
for(i=0; i<k; i++)
|
|
if(s[i].cscore<60)
|
|
printf("\t\t\t%d %s %.1lf\n",s[i].num,s[i].name,s[i].cscore);
|
|
printf("\n\n");
|
|
}
|
|
void average() { //平均分、及格率
|
|
system("cls");
|
|
k=0;
|
|
double sum=0,average,jgl;
|
|
int a=0;
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
}
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=EOF) {
|
|
k++;
|
|
}
|
|
for(i=0; i<k; i++){
|
|
sum+=s[i].cscore;
|
|
}
|
|
average=sum/k;
|
|
printf("平均分为:%.1lf\n",average);
|
|
for(i=0; i<k; i++)
|
|
if(s[i].cscore>=60){
|
|
a++;
|
|
}
|
|
jgl=((double)a/(double)k)*100;
|
|
printf("及格率为:%.1lf%%\n",jgl);
|
|
}
|
|
|
|
void rank() { //排序
|
|
struct stu t;
|
|
k=0;
|
|
system("cls");
|
|
if((fp=fopen("stuinfo","r"))==NULL) {
|
|
printf("打不开文件!\n");
|
|
}
|
|
while(fscanf(fp,"%d%s%lf",&s[k].num,s[k].name,&s[k].cscore)!=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 %.1lf\n",i+1,s[i].num,s[i].name,s[i].cscore);
|
|
}
|