From 3064fa6ed634e227cf951703edb1552928c8a7cb Mon Sep 17 00:00:00 2001 From: pgpt9ufz8 <623062069@qq.com> Date: Sun, 22 Oct 2023 20:51:00 +0800 Subject: [PATCH] ADD file via upload --- 成绩管理.c | 448 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 448 insertions(+) create mode 100644 成绩管理.c diff --git a/成绩管理.c b/成绩管理.c new file mode 100644 index 0000000..084b7e2 --- /dev/null +++ b/成绩管理.c @@ -0,0 +1,448 @@ +#include +#include +#include + + + +//结构体定义 +typedef struct Node{ + int id;//学号 + char name[100];//名 + char sex[10];//性别 + int ch,ma,en;//语数英 + int sum;//总分 + + //指针域 + struct Node *next; + }node; + +node List;//连表 + +//文件读取 +int readFile(node *L); + +void printfAddStuInfo();//界面 +void insertStuInfo(node *L,node e);//功能 + +//主页面--菜单 +void welcome(); +//退出程序 +void goodBye(); +//删除学生信息 +void deleteStuInfo(node *pr); +//打印删除学生信息 +void printDeleteStuInfo(node *L); +//修改学生信息 +void printFixStuInfo(node *L); +//按姓名进行查找 +node * searchStuInfoByName(char name[],node *L); +//按学号进行查找 +node * searchStuInfoById(int id,node *L); +////查询学生信息 +void printSearchStuInfo(node *L); + //保存文件 +int saveFile(node *L); +//添加功能的实现 +void insertStuInfo(node *L,node e);//功能 +//增加学生信息 +void printAddStuInfo();//输出界面 +//输出所有学生信息 +void printStuInfo(node *L); +//文件输入 +int readFile(Node *L); +//删除 +void deletestudentInfo(); +//退出 +void goodBye(); +//查询 +void searchstudentInfo(); +//输出 +void printstudentInfo(node *L); +//添加 +void addstudentInfo(node *L); +//修 +void fixstudentInfo(node *L); +//查询 +void searchstudentInfo(node *L); +//输出 +void printstudentInfo(node *L); +//退 +void goodBye(); + +int main(){ + int choice = 0; + readFile(&List); + // scanf("%d",&choice); + while(true){ + welcome(); + scanf("%d",&choice); + switch (choice) + { + case 1://添加 + printAddStuInfo(); + break; + case 2://删除 + printDeleteStuInfo(&List); + break; + case 3://修改 + printFixStuInfo(&List); + break; + case 4://查询 + printSearchStuInfo(&List); + break; + case 5://输出 + printstudentInfo(&List); + break; + case 0://退出 + goodBye(); + break; + // default: + // break; + } + printf("是否继续操作!!!!(yse:1/no:0)(1/0)\n"); + scanf("%d",&choice); + if(choice==0){ + break; + } + } + return 0; +} + +//主菜单页面 +void welcome(){ + printf("***********************\n"); + printf("*** 学生成绩管理系统 ***\n"); + printf("***作者:姜超 刘瑞斌****\n"); + printf("***添加学生信息————1****\n"); + printf("***删除学生信息————2****\n"); + printf("***修改学生信息————3****\n"); + printf("***查询学生信息————4****\n"); + printf("***输出学生信息————5****\n"); + printf("***退出管理系统————0****\n"); + printf("**请输入对应数字(0-5)***\n"); +} + +////添加 +//void addstudentInfo(){ +// printf("----添加学生信息\n"); +//} +////删除 +//void deletestudentInfo(){ +// printf("----删除学生信息\n"); +//} +////修修改 +//void fixstudentInfo(){ +// printf("----修改学生信息\n"); +//} +////查询 +//void searchstudentInfo(){ +// printf("----查询学生信息\n"); +//} +//输出 +void printstudentInfo(node *L){ + // printf("----输出学生信息\n"); + system("cls"); + node *p = L->next; + printf("_______________________________________________________"); + printf("|学 号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("_______________________________________________________"); + if(p!=NULL){ + while(p!=NULL){ + printf("%d%s\t|%s\t|%d\t|%d\t|%d\t|%d",p->id,p->name,p->sex,p->ch,p->ma,p->en,p->sum); + printf("______________________________________________________"); + p=p->next; + } + } +} + + +//文件输入 +int readFile(Node *L){ + FILE *fpr=fopen("studentInfo.txt","r"); + node st; + node *s; + node *t=L; + + if(fpr==NULL){ + return 0; + }else{ + while(fscanf(fpr,"%d %s %s %d %d %d %d\n",&st.id,st.name,st.sex,&st.ch,&st.ma,&st.en,&st.sum)!=EOF){ + s=(node *)malloc(sizeof(node)); + *s = st; + + t->next=s; + t=s; + t->next=NULL; + } + } + fclose(fpr); + return 1; + } + +//输出所有学生信息 +void printStuInfo(node *L){ + system("cls"); + node *p=L->next; + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + if(p!=NULL){ + + while(p!=NULL){ + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->id,p->name,p->sex,p->ch,p->ma,p->en,p->sum); + printf("________________________________________________________\n"); + p=p->next; + } + } +} + +//增加学生信息 +void printAddStuInfo(){ + // + system("cls"); + node st; + printf("请输入新增学生相关信息\n"); + printf("学号:"); + scanf("%d",&st.id); + printf("姓名:"); + scanf("%s",st.name); + printf("性别:"); + scanf("%s",st.sex); + printf("语文:"); + scanf("%d",&st.ch); + printf("数学:"); + scanf("%d",&st.ma); + printf("英语:"); + scanf("%d",&st.en); + st.sum=st.ch+st.ma+st.en; + + insertStuInfo(&List,st); + +} + +//保存文件 +int saveFile(node *L){ + FILE *fpw=fopen("studentInfo.txt","w"); + if(fpw==NULL) return 0; + node *p=L->next; + while(p!=NULL){ + fprintf(fpw,"%d %s %s %d %d %d %d\n",p->id,p->name,p->sex,p->ch,p->ma,p->en,p->sum); + p=p->next; + } + fclose(fpw);//关闭文件指针 + return 1; +} + +//再在学生信息的增加过程中添加文件数据的保存操作。 +void insertStuInfo(node *L,node e){ + //头插法 + node *h=L; + node *s=(node *)malloc(sizeof(node)); + *s=e; + + s->next=h->next; + h->next=s; + + //保存文件 + saveFile(L); +} + +////查询学生信息 +void printSearchStuInfo(node *L){ + system("cls"); + int choice=0; + int id; + char name[50]; + node *st; + printf("按学号查询----- 1\n"); + printf("按姓名查询----- 2\n"); + printf("请输入查询方式:"); + scanf("%d",&choice); + + if(choice == 1){ + printf("请输入要查询的学号:"); + scanf("%d",&id); + st=searchStuInfoById(id,L); + + if(st==NULL){ + printf("查无此人!\n"); + }else{ + st=st->next; + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",st->id,st->name,st->sex,st->ch,st->ma,st->en,st->sum); + printf("________________________________________________________\n"); + } + }else if(choice ==2){ + printf("请输入要查询的姓名:"); + scanf("%s",name); + st=searchStuInfoByName(name,L); + + if(st==NULL){ + printf("查无此人!\n"); + }else{ + st=st->next; + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",st->id,st->name,st->sex,st->ch,st->ma,st->en,st->sum); + printf("________________________________________________________\n"); + } + } + +} + +//按学号进行查找 +node * searchStuInfoById(int id,node *L){ + + node *p=L; + + while(p->next!=NULL){ + + if(p->next->id==id){ + return p; + } + + p=p->next; + } + + return NULL; +} +//按姓名进行查找 +node * searchStuInfoByName(char name[],node *L){ + node *p=L; + + while(p->next!=NULL){ + + if(strcmp(name,p->next->name)==0){ + return p; + } + + p=p->next; + } + + return NULL; +} + + +//修改学生信息 +void printFixStuInfo(node *L){ + system("cls"); + int id; + int choice=-1; + + printf("请输入要查找的学生学号"); + scanf("%d",&id); + node *st=searchStuInfoById(id,L); + + if(st==NULL){ + printf("查无此人!"); + return; + } + + st=st->next; + + while(1){ + system("cls"); + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",st->id,st->name,st->sex,st->ch,st->ma,st->en,st->sum); + printf("________________________________________________________\n"); + printf("修改姓名---- 1\n"); + printf("修改性别---- 2\n"); + printf("修改语文---- 3\n"); + printf("修改数学---- 4\n"); + printf("修改英语---- 5\n"); + + printf("请输入要修改的信息: "); + scanf("%d",&choice); + + switch(choice){ + case 1: + printf("请输入姓名:"); + scanf("%s",st->name); + break; + case 2: + printf("请输入性别:"); + scanf("%s",st->sex); + break; + case 3: + printf("请输入语文:"); + scanf("%d",&st->ch); + break; + case 4: + printf("请输入数学:"); + scanf("%d",&st->ma); + break; + case 5: + printf("请输入英语:"); + scanf("%d",&st->en); + break; + } + st->sum=st->ch+st->ma+st->en; + printf("是否继续修改学生信息?(y-1 / n-0)\n"); + scanf("%d",&choice); + if(choice == 0){ + break; + } + } + + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",st->id,st->name,st->sex,st->ch,st->ma,st->en,st->sum); + printf("________________________________________________________\n"); + + //保存文件信息 + saveFile(L); +} + + +//打印删除学生信息 +void printDeleteStuInfo(node *L){ + system("cls"); + int id; + + node *p; + + printf("请输入要查找的学生学号"); + scanf("%d",&id); + node *st=searchStuInfoById(id,L); + p=st; + + if(st==NULL){ + printf("查无此人!"); + return; + } + + st=st->next; + printf("________________________________________________________\n"); + printf("|学号\t|姓名\t|性别\t|语文\t|数学\t|英语\t|总分\t|\n"); + printf("________________________________________________________\n"); + printf("%d|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",st->id,st->name,st->sex,st->ch,st->ma,st->en,st->sum); + printf("________________________________________________________\n"); + + deleteStuInfo(p); + saveFile(L); + +} +//删除学生信息 +void deleteStuInfo(node *pr){ + node *s=pr->next; + + pr->next=s->next; + s->next=NULL; + + free(s);//释放结点空间 + +} + + +//退出程序 +void goodBye(){ + system("cls"); + printf("欢迎下次使用~\n"); + exit(0);//结束程序 +} \ No newline at end of file