回答 (1)
这个是我自己写的..我也在学习中,不足之处请谅解:#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>void newinf(void);void showinf(void);void insertinf(void);void deleteinf(void);void saveinf(void);void infoinf(void);void sortinf(void); void searchinf(void);void menu(void);struct inf{ int number; char name[80]; int score; inf * prev,* next;};inf * head,* tail;int high,low,average;int total=0;void main(void){ system("cls"); system("color 1a"); system("title 成绩管理系统"); menu(); int choice; scanf("%d",&choice); system("cls"); switch(choice){ case 0: exit(0); break; case 1: newinf(); main(); break; case 2: searchinf(); main(); break; case 3: insertinf(); main(); break; case 4: deleteinf(); main(); break; case 5: sortinf(); main(); break; case 6: showinf(); main(); break; case 7: //数据统计 printf("共有学生%d人\n",total); system("pause"); main(); break; case 8: //保存 saveinf(); main(); break; }}void newinf(void){ inf * temp; temp=(inf *)malloc(sizeof(inf)); printf("请输入学号\n"); scanf("%d",&temp->number); printf("请输入姓名\n"); scanf("%s",&temp->name); printf("请输入成绩\n"); scanf("%d",&temp->score); temp->next=NULL; if(head==NULL){ temp->prev=NULL; head=temp; tail=temp; } else{ tail->next=temp; temp->prev=tail; tail=temp; } total++;}void showinf(void){ inf * temp; temp=head; if(head==NULL){ printf("数据不存在\n"); system("pause"); main(); } do{ printf("学号%d 姓名%s 成绩%d\n",temp->number,temp->name,temp->score); temp=temp->next; } while(temp!=NULL); system("pause");}void insertinf(void){ if(head==NULL){ printf("数据不存在\n无法插入,请选择 1.增加记录\n"); system("pause"); main(); } int input,count=0; inf * temp,*search,*temp2; printf("请输入在第几条后插入\n"); scanf("%d",&input); while(input>total||input<=0){ printf("输入错误请重新输入"); scanf("%d",&input); }; temp=(inf *)malloc(sizeof(inf)); printf("请输入学号\n"); scanf("%d",&temp->number); printf("请输入姓名\n"); scanf("%s",&temp->name); printf("请输入成绩\n"); scanf("%d",&temp->score); search=head; while(search!=NULL){ count++; if(input==count){ temp2=search->next; search->next=temp; temp->prev=search; temp->next=temp2; if(temp2!=NULL){ temp2->prev=temp; } } search=search->next; }; total++;}void deleteinf(void){ if(head==NULL){printf("数据不存在!\n");<br> system("pause"); <br> main();} int input,count=0; inf * temp,*temp2,*search; printf("请输入删除第几条\n"); scanf("%d",&input); while(input>total||input<=0){ printf("输入错误请重新输入"); scanf("%d",&input);}; search=head; while(search!=NULL){count++;<br> if(input==count){if(count==1){head=search->next;} temp=search->prev; temp2=search->next; if(temp!=NULL){ temp->next=temp2;} if(temp2!=NULL){ temp2->prev=temp;} free(search);} search=search->next;}; total--;}void searchinf(void){if(head==NULL){<br> printf("数据不存在!\n");<br> system("pause"); <br> main();} inf * temp; int choice,number,score; char name[80]; temp=head; printf("请选择查找方式:\n1.按学号查找\n2.按姓名查找\n3.按成绩查找\n"); scanf("%d",&choice); printf("请输入对应信息\n"); switch(choice){case 1:<br> scanf("%d",&number);<br> while(temp!=NULL){if(temp->number==number){printf("学号%d 姓名%s 成绩%d\n",temp->number,temp->name,temp->score);} temp=temp->next;}; break; case 2: getchar(); gets(name); while(temp!=NULL){if(strcmp(temp->name,name)==0){printf("学号%d 姓名%s 成绩%d\n",temp->number,temp->name,temp->score);} temp=temp->next;}; break; case 3: scanf("%d",&score); while(temp!=NULL){ if(temp->score==score){printf("学号%d 姓名%s 成绩%d\n",temp->number,temp->name,temp->score);} temp=temp->next;}; break;} system("pause"); }void sortinf(void){inf *temp,*temp2;<br> int number,score;<br> char name[80];<br> temp=head;<br> if(head==NULL){<br> printf("数据不存在\n");<br> system("pause"); <br> main();} for(int i=1;i<=total*total;i++){ if(temp->next==NULL){temp=head;<br> continue;} temp2=temp->next; if(temp->number>temp2->number){ name=temp->name; score=temp->score; number=temp->number; temp->name=temp2->name; temp->score=temp2->score; temp->number=temp2->number; temp2->name=name; temp2->score=score; temp2->number=number;} temp=temp->next;} printf("排序完成\n"); system("pause"); }void menu(void){ system("cls"); printf(" ********************************************************************\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * 成绩管理系统 *\n"); printf(" * *\n"); printf(" * *\n"); printf(" * *\n"); printf(" ********************************************************************\n"); printf("1.增加记录\n2.查找记录\n3.插入记录\n4.删除记录\n5.记录排序\n6.查看记录\n7.数据统计\n8.保存记录\n0.退出\n");}void saveinf(void){ printf("请注意,保存信息将覆盖原文件!\n确认请输入y:\n"); char a; getchar(); scanf("%c",&a); if(a=='y'||a=='Y') { FILE *file; inf *temp; file=fopen("save.txt","w+"); temp=head; while(temp!=NULL) { fprintf(file,"学号:%d 姓名:%s 成绩:%d\n",temp->number,temp->name,temp->score); temp=temp->next; } printf("保存成功!"); system("pause"); main(); } else { main(); }}
评论 (2)
非常感谢您的详细建议!我很喜欢。
不错的回答我认为你可以在仔细的回答一下
分享你的回答
提问者
相关问题
母亲节特惠:花束买一送一
精选花束,为母亲送上最温馨的祝福