From fda7e9a9160c9b5621737c8f0e13dc8c1fa97dd7 Mon Sep 17 00:00:00 2001 From: pgpt9ufz8 <623062069@qq.com> Date: Sun, 22 Oct 2023 20:50:34 +0800 Subject: [PATCH] ADD file via upload --- 成绩管理系统.cpp | 447 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 447 insertions(+) create mode 100644 成绩管理系统.cpp diff --git a/成绩管理系统.cpp b/成绩管理系统.cpp new file mode 100644 index 0000000..17f4dcf --- /dev/null +++ b/成绩管理系统.cpp @@ -0,0 +1,447 @@ +#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);// +}