From 1da89727db72168135a1275eda9582938713c668 Mon Sep 17 00:00:00 2001 From: "2675833891@qq.com" <2675833891@qq.com> Date: Tue, 8 Jan 2019 17:06:55 +0800 Subject: [PATCH] second commit --- f2.c | 454 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 454 insertions(+) create mode 100644 f2.c diff --git a/f2.c b/f2.c new file mode 100644 index 0000000..77b1ff5 --- /dev/null +++ b/f2.c @@ -0,0 +1,454 @@ +#include +#include +#include +#include +#define N 100 +struct student +{ + char no[9]; + char name[25]; + char sex[10]; + int age; + char jiguan[25]; + char xibie[25]; + char zhuanye[25]; + int ban; +}stu[N]; +void menu()//菜单函数 +{ + int choice,w1; + void add(); + void find(); + void shanchu(); + void change(); + void tongji(); + void read(); + void input();//函数声明 + do{ + puts("\t*********************"); + puts("\t 欢迎使用学籍管理系统"); + puts("\t 1,录入学生资料"); + puts("\t 2,查找学生资料"); + puts("\t 3,删除学生资料"); + puts("\t 4,修改学生资料"); + puts("\t 5,按学号或专业输出学生资料"); + puts("\t 6,查看所有学生资料"); + puts("\t 7,退出系统"); + puts("\t**********************"); + printf("想选择的功能"); + scanf("%d,&choice"); + if(choice<1||choice>8) + { + w1=1; + system("cls"); + printf("菜单选择错误,请重新选择"); + } + else w1=0; + + + } while(w1==1); + switch(choice)//根据用户的菜单选择调用相应的函数 + { + case 1: + add(); + break; + case 2: + find(); + break; + case 3: + shanchu(); + break; + case 4: + change(); + break; + case 5: + tongji(); + break; + case 6: + read(); + break; + case 7: + break; + default:exit(0); + } + } + int load() + { + FILE *fp; + int i; + if((fp=fopen("results.txt","rb"))==NULL) + { + printf("文件打开错误"); + return 0; + } + for(i=0;!feof(fp);i++) + fread(&stu[i],sizeof(struct student),1,fp); + fclose(fp); + return (i-1); + } + //保存函数 + void save(int n) + { + int i; + FILE *fp; + if((fp=fopen("results.txt","wb"))==NULL) + { + printf("文件打开错误"); + } + for(i=0;i2) + { + xz=1; + system("cls"); + printf("输入错误,请重新选择\n"); + } + else xz=0; + } while(xz==1); + switch(choice) + { + case 1: + menu(); + break;//调用菜单函数 + case 2: + exit(0); + break;//退出系统 + } +} + } + //录入学生信息 + void add() + { + FILE *fp; + int n,i,m; + n=load(); + if((fp=fopen("results.txt","wb"))==NULL) + { + printf("文件打开错误\n"); + exit(0); + + } + printf("你想录入多少个学生信息"); + scanf("%d",&m); + for(i=0;i2) + { + xz=1; + system("cls"); + printf("输入错误,请重新输入\n"); + } + else xz=0; + }while(xz==1); + switch(choice) + { + case 1: + menu(); + break; + case 2: + exit(0); + break; + } + } +} + + + + //查找函数 + void find() + { + int menu(); + int n,i; + char m[9]; + n=load(); + printf("\t\t欢迎使用学号查找功能\n请输入你需要查找的学生的学号:"); + scanf("%s",&m); + for(i=0;i2) + { + xz=1; + system("cls"); + printf("输入错误,请重新选择\n"); + + } + else xz=0; + }while(xz==1); + switch(choice) + { + case 1: + menu(); + break; + case 2: + exit(0); + break; + } + } + } + //修改函数 + void change() + { + int n,i,j; + char m[9]; + n=load(); + printf("欢迎使用修改功能\n输入你要修改学生的学号:"); + scanf("%s",&m); + for(i=0;i2) + { + xz=1; + system("cls"); + printf("输入错误,请重新选择\n"); + } + else xz=0; + }while(xz==1); + switch(choice) + { + case 1: + menu(); + break; + case 2: + exit(0); + break; + } +} +} +//统计函数 +void tongji() +{ + int k,i,n; + struct student t; + system("cls"); + printf("学号 专业 籍贯\n"); + for(k=0;kstu[i+1].no) + t=stu[i]; + stu[i]=stu[i+1]; + stu[i+1]=t; + } + } + for(i=0;i2) + { + xz=1; + system("cls"); + printf("输入错误,请重新选择\n"); + } + else xz=0; + }while(xz==1); + switch(choice) + { + case 1: + menu(); + break; + case 2: + exit(0); + break; + + } + } + + + } + //删除函数 + void shanchu() + { + int n,i,j; + char m[9]; + n=load(); + printf("输入你要删除学生的学号"); + scanf("%s",&m); + for(i=0;i2) + { + xz=1;system("cls"); + printf("输入错误,请重新选择\n"); + } + else xz=0; + + } while(xz==1); + switch(choice) + { + case 1: + menu(); + break; + case 2: + exit(0); + break; + } + } + } + int main() + { + menu(); + } + + +