From e3407f2e3c3b51ba54a498ac551c7e087fdf1d80 Mon Sep 17 00:00:00 2001 From: "18408000523@stu.hut.edu.cn" <18408000523@stu.hut.edu.cn> Date: Thu, 10 Jan 2019 20:03:23 +0800 Subject: [PATCH] second --- Untitled2.cpp | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 Untitled2.cpp diff --git a/Untitled2.cpp b/Untitled2.cpp new file mode 100644 index 0000000..2e510cd --- /dev/null +++ b/Untitled2.cpp @@ -0,0 +1,251 @@ +#include +#include +#include +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=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=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=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=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