日程管理c语言编写 求代码 有重谢
2个回答
2016-06-25
展开全部
#include"stdio.h"#include"stdlib.h"#include"string.h"intshoudsave=0;/**/structstudent{char()num[10];/*学号*/char()name[20];char()sex[4];intcgrade;intmgrade;integrade;inttotle;intave;charneartime[10];/*最近更新时间*/};typedefstructnode{structstudentdata;structnode*next;}Node,*Link;voidmenu(){printf("********************************************************************************");printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n");printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");printf("\t5保存学生资料\t\t\t\t\t0退出系统\n");printf("********************************************************************************\n");}voidprintstart(){printf("-----------------------------------------------------------------------\n");}voidWrong(){printf("\n=====>提示:输入错误!\n");}voidNofind(){printf("\n=====>提示:没有找到该学生!\n");}voidprintc()/*本函数用于输出中文*/{printf("学号\t姓名性别英语成绩数学成绩C语言成绩总分平均分\n");}voidprinte(Node*p)/*本函数用于输出英文*/{printf("%-12s%s\t%s\t%d\t%d\t%d\t%d\t%d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave);}Node*Locate(Linkl,charfindmess[],charnameornum[])/*该函数用于定位连表中符合要求的接点,并返回该指针*/{Node*r;if(strcmp(nameornum,"num")==0)/*按学号查询*/{r=l->next;while(r!=NULL){if(strcmp(r->data.num,findmess)==0)returnr;r=r->next;}}elseif(strcmp(nameornum,"name")==0)/*按姓名查询*/{r=l->next;while(r!=NULL){if(strcmp(r->data.name,findmess)==0)returnr;r=r->next;}}return0;}voidAdd(Linkl)/*增加学生*/{Node*p,*r,*s;charnum[10];r=l;s=l->next;while(r->next!=NULL)r=r->next;/*将指针置于最末尾*/while(1){printf("请你输入学号(以'0'返回上一级菜单:)");scanf("%s",num);if(strcmp(num,"0")==0)break;while(s){if(strcmp(s->data.num,num)==0){printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4修改'!\n",num);printstart();printc();printe(s);printstart();printf("\n");return;}s=s->next;}p=(Node*)malloc(sizeof(Node));strcpy(p->data.num,num);printf("请你输入姓名:");scanf("%s",p->data.name);getchar()();printf("请你输入性别:");scanf("%s",p->data.sex);getchar()();printf("请你输入c语言成绩:");scanf("%d",&p->data.cgrade);getchar()();printf("请你输入数学成绩:");scanf("%d",&p->data.mgrade);getchar();printf("请你输入英语成绩:");scanf("%d",&p->data.egrade);getchar();p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;p->data.ave=p->data.totle/3;/*信息输入已经完成*/p->next=NULL;r->next=p;r=p;shoudsave=1;}}voidQur(Linkl)/*查询学生*/{intsel;charfindmess[20];Node*p;if(!l->next){printf("\n=====>提示:没有资料可以查询!\n");return;}printf("\n=====>1按学号查找\n=====>2按姓名查找\n");scanf("%d",&sel);if(sel==1)/*学号*/{printf("请你输入要查找的学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){printf("\t\t\t\t查找结果\n");printstart();printc();printe(p);printstart();}elseNofind();}elseif(sel==2)/*姓名*/{printf("请你输入要查找的姓名:");scanf("%s",findmess);p=Locate(l,findmess,"name");if(p){printf("\t\t\t\t查找结果\n");printstart();printc();printe(p);printstart();}elseNofind();}elseWrong();}voidDel(Linkl)/*删除*/{intsel;Node*p,*r;charfindmess[20];if(!l->next){printf("\n=====>提示:没有资料可以删除!\n");return;}printf("\n=====>1按学号删除\n=====>2按姓名删除\n");scanf("%d",&sel);if(sel==1){printf("请你输入要删除的学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);printf("\n=====>提示:该学生已经成功删除!\n");shoudsave=1;}elseNofind();}elseif(sel==2){printf("请你输入要删除的姓名:");scanf("%s",findmess);p=Locate(l,findmess,"name");if(p){r=l;while(r->next!=p)r=r->next;r->next=p->next;free(p);printf("\n=====>提示:该学生已经成功删除!\n");shoudsave=1;}elseNofind();}elseWrong();}voidModify(Linkl){Node*p;charfindmess[20];if(!l->next){printf("\n=====>提示:没有资料可以修改!\n");return;}printf("请你输入要修改的学生学号:");scanf("%s",findmess);p=Locate(l,findmess,"num");if(p){printf("请你输入新学号(原来是%s):",p->data.num);scanf("%s",p->data.num);printf("请你输入新姓名(原来是%s):",p->data.name);scanf("%s",p->data.name);getchar();printf("请你输入新性别(原来是%s):",p->data.sex);scanf("%s",p->data.sex);printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade);scanf("%d",&p->data.cgrade);getchar();printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade);scanf("%d",&p->data.mgrade);getchar();printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade);scanf("%d",&p->data.egrade);p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgrade;p->data.ave=p->data.totle/3;printf("\n=====>提示:资料修改成功!\n");shoudsave=1;}elseNofind();}voidDisp(Linkl){intcount=0;Node*p;p=l->next;if(!p){printf("\n=====>提示:没有资料可以显示!\n");return;}printf("\t\t\t\t显示结果\n");printstart();printc();printf("\n");while(p){printe(p);p=p->next;}printstart();printf("\n");}voidTongji(Linkl){Node*pm,*pe,*pc,*pt,*pa;/*用于指向分数最高的接点*/Node*r=l->next;if(!r){printf("\n=====>提示:没有资料可以统计!\n");return;}pm=pe=pc=pt=pa=r;while(r!=NULL){if(r->data.cgrade>=pc->data.cgrade)pc=r;if(r->data.mgrade>=pm->data.mgrade)pm=r;if(r->data.egrade>=pe->data.egrade)pe=r;if(r->data.totle>=pt->data.totle)pt=r;if(r->data.ave>=pa->data.ave)pa=r;r=r->next;}printf("------------------------------统计结果--------------------------------\n");printf("总分最高者:\t%s%d分\n",pt->data.name,pt->data.totle);printf("平均分最高者:\t%s%d分\n",pa->data.name,pa->data.ave);printf("英语最高者:\t%s%d分\n",pe->data.name,pe->data.egrade);printf("数学最高者:\t%s%d分\n",pm->data.name,pm->data.mgrade);printf("c语言最高者:\t%s%d分\n",pc->data.name,pc->data.cgrade);printstart();}voidSort(Linkl){Linkll;Node*p,*rr,*s;ll=(Link)malloc(sizeof(Node));/*用于做新的连表*/ll->next=NULL;if(l->next==NULL){printf("\n=====>提示:没有资料可以排序!\n");return;}p=l->next;while(p){s=(Node*)malloc(sizeof(Node));/*新建接点用于保存信息*/s->data=p->data;s->next=NULL;rr=ll;while(rr->next!=NULL&&rr->next->data.totle>=p->data.totle)rr=rr->next;if(rr->next==NULL)rr->next=s;else{s->next=rr->next;rr->next=s;}p=p->next;}free(l);l->next=ll->next;printf("\n=====>提示:排序已经完成!\n");}voidSave(Linkl){FILE*fp;Node*p;intflag=1,count=0;fp=fopen("c:\\student","wb");if(fp==NULL){printf("\n=====>提示:重新打开文件时发生错误!\n");exit(1);}p=l->next;while(p){if(fwrite(p,sizeof(Node),1,fp)==1){p=p->next;count++;}else{flag=0;break;}}if(flag){printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count);shoudsave=0;}fclose(fp);}voidmain(){Linkl;/*连表*/FILE*fp;/*文件指针*/intsel;charch;charjian;intcount=0;Node*p,*r;printf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501黄欢(32号)\n");l=(Node*)malloc(sizeof(Node));l->next=NULL;r=l;fp=fopen("C:\\student","rb");if(fp==NULL){printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n");scanf("%c",&jian);if(jian=='y'||jian=='Y')fp=fopen("C:\\student","wb");elseexit(0);}printf("\n=====>提示:文件已经打开,正在导入记录\n");while(!feof(fp)){p=(Node*)malloc(sizeof(Node));if(fread(p,sizeof(Node),1,fp))/*将文件的内容放入接点中*/{p->next=NULL;r->next=p;r=p;/*将该接点挂入连中*/count++;}}fclose(fp);/*关闭文件*/printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count);while(1){menu();printf("请你选择操作:");scanf("%d",&sel);if(sel==0){if(shoudsave==1){getchar();printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n");scanf("%c",&ch);if(ch=='y'||ch=='Y')Save(l);}printf("\n=====>提示:你已经退出系统,再见!\n");break;}switch(sel){case1:Add(l);break;/*增加学生*/case2:Del(l);break;/*删除学生*/case3:Qur(l);break;/*查询学生*/case4:Modify(l);break;/*修改学生*/case5:Save(l);break;/*保存学生*/case9:printf("\t\t\t==========帮助信息==========\n");break;default:Wrong();getchar();break;}}}/**/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询