C语言学生个人消费管理系统_第1页
C语言学生个人消费管理系统_第2页
C语言学生个人消费管理系统_第3页
C语言学生个人消费管理系统_第4页
C语言学生个人消费管理系统_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 C 语言学生个人消费管理系统代码部分:/*#include */#include #include #include #define LEN sizeof(struct scorenode)#define DEBUGstruct scorenodeint number;/*学号*/char name10;/*姓名*/int xiaofei;/*消费情况*/struct scorenode *next;typedef struct scorenode score;int n,k;/*n,k 为全局变量,本程序中的函数均可 *p3 以使用它*/ 2 void menu();score *creat(void);score *load(score *head);score *search(score *head);score *del(score *head);score *add(score *head,score *stu);void print(score *head);save(score *p1);/*=*/*=创建链表,此函数带回一个指向链表头的指针=*/score *creat(void)score *head;score *p1,*p2,*p3,*max;int i,j;char t10;n=0; 3 p1=p2=p3=(score *)malloc(LEN);/*head=p3; 开辟一个新单元*/printf(“please input students information,input 0 exit!n“);repeat1: printf(“please input students number(number0):“);/*输入学号,学号应大于 0*/scanf(“ %d“,while(p1-numbernumber);/*输入学号为字符或小于 0 时,程序报错,提示重新输入学号*/if(p1-number=0)goto end;/*当输入的学号为 0 时,转到末尾,结束创建链表*/elsep3=head; 4 if(n0)for(i=0;inumber!=p3-number)p3=p3-next;elseprintf(“number repeate,please input again!n“);goto repeat1;/*当输入的学号已经存在,程序报错,返回前面重新输入*/printf(“please input students name:“);scanf(“%s“,/*输入学生姓名 */printf(“please input students consume money:“);/*输入消费情况;*/ 5 scanf(“%d“,while(p1-number!=0)n=n+1;if(n=1)head=p1;elsep2-next=p1;p2=p1;p1=(score *)malloc(LEN);printf(“please input students information,input 0 exit!n“);repeat2:printf(“please input students number(number0):“);scanf(“%d“,/*输入学号,学号应大于 0*/while(p1-numbernumber); 6 /*输入学号为字符或小于 0 时,程序报错,提示重新输入学号*/if(p1-number=0)goto end;/*当输入的学号为 0 时,转到末尾,结束创建链表*/elsep3=head;if(n0)for(i=0;inumber!=p3-number)p3=p3-next;elseprintf(“number repeate,please input again!n“);goto repeat2;/*当输入的学号已经存在,程序报错,返回前面重新输入*/ 7 printf(“please input students name:“);scanf(“%s“,/*输入学生姓名 */printf(“please input students consume money:“);scanf(“%d“,/*输入消费情况; */end: p1=head;p3=p1;for(i=1;inext;if(max-numberp1-number)k=max-number;max-number=p1-number;p1-number=k;/*交换前后结点中的学号值,使得学号大者移到后面 8 的结点中*/strcpy(t,max-name);strcpy(max-name,p1-name);strcpy(p1-name,t);/*交换前后结点中的姓名,使之与学号相匹配*/*交换前后结点中的消费情况,使之与学号相匹配*/max=head;p1=head;/*重新使 max,p 指向链表头*/p2-next=NULL;/*链表结尾*/printf(“input students num:%d ge!n“,n);getch();return(head);/*=*/ 9 /*=从文件读入学生记录=*/score *load(score *head)score *p1,*p2;int m=0;char filepn10;FILE *fp;printf(“please input files postion and its name:“);scanf(“%s“,filepn);/*输入文件路径及名称*/if(fp=fopen(filepn,“r+“)=NULL)printf(“cant open this file!n“);getch();return 0;else 10 p1=(score *)malloc(LEN); /*开辟一个新单元*/fscanf(fp,“%d%s%dn“,printf(“|%dt|%st|%dtn“,p1-number,p1-name,p1-xiaofei);/*文件读入与显示*/head=NULL;don=n+1;if(n=1)head=p1;elsep2-next=p1;p2=p1;p1=(score *)malloc(LEN); /*开辟一个新单元*/fscanf(fp,“%d%s%dn“,printf(“|%dt|%st|%dtn“,p1-number,p1-name,p1-xiaofei); 11 /*文件读入与显示 */while(!feof(fp);p2-next=p1;p1-next=NULL;n=n+1;printf(“-n“);/*表格下线*/getch();fclose(fp);/*结束读入,关闭文件 */return (head);/*=*/*=查询学生消费=*/score *search(score *head) 12 int number;score *p1,*p2;printf(“input the students number of searching:“);scanf(“%d“,getchar();while(number!=0)if(head=NULL)printf(“n nobody information!n“);return(head);printf(“-n“);printf(“|numbert|namet|consumet n“);printf(“-n“);/*打印表格域*/p1=head;while(number!=p1-numberp1=p1-next; 13 if(number=p1-number)printf(“|%dt|%st|%dtn“,p1-number,p1-name,p1-xiaofei);printf(“-n“);/*打印表格域*/elseprintf(“%dthis student not exist!n“,number);printf(“input the students number of searching:“);scanf(“%d“,getchar();printf(“already exit!n“);getchar();return(head);/*= 14 =*/*=删除学生资料=*/score *del(score *head)score *p1,*p2;int number;printf(“input the students number of deleting(input 0 exit):“);scanf(“%d“,getchar();while(number!=0)/*输入学号为 0 时退出*/if(head=NULL)printf(“nnobody information!n“);return(head);p1=head; 15 while(number!=p1-numberp1=p1-next; /*p1 后移一个结点*/if(number=p1-number)/*找到了*/if(p1=head)head=p1-next;/*若 p1 指向的是首结点,把地二个结点地址赋予 head*/elsep2-next=p1-next;/*否则将下一个结点地址 赋给前一结点地址*/printf(“delete number:%dn“,number);n=n-1; 16 elseprintf(“%d student not exist!n“,number);/*找不到该结点*/printf(“input the students number of deleting:“);scanf(“%d“,getchar();#ifdef DEBUGprintf(“already exitn“);#endifprintf(“now how many students:%d ge!n“,n);getch();return(head);/*=*/*=*/ 17 score *add(score *head,score *stu)score *p0,*p1,*p2,*p3,*max;int i,j;char t10;p3=stu=(score *)malloc(LEN);/*开辟一个新单元*/printf(“ninput the students information of adding!“);repeat4: printf(“please input the students number(number0):“);scanf(“%d“,/*输入学号,学号应大于 0*/while(stu-numbernumber);/*输入错误,重新输入学号*/*/if(stu-number=0) 18 goto end2;/*当输入的学号为 0 时,转到末尾,结束追加*/elsep3=head;if(n0)for(i=0;inumber!=p3-number)p3=p3-next;elseprintf(“number repeat,please input again!n“);goto repeat4;/*当输入的学号已经存在,程序报错,返回前面重新输入*/ 19 /*/printf(“input the students name:“);scanf(“%s“,stu-name); /*输入学生姓名*/printf(“please input the consuming:“);scanf(“%d“, p1=head;p0=stu;if(head=NULL)head=p0;p0-next=NULL;/*当原来链表为空时,从首结点开始存放资料 */else/*原来链表不为空*/if(p1-next=NULL)/*找到原来链表的末尾*/p1-next=p0;p0-next=NULL;/*将它与新开单元相连接*/ 20 elsewhile(p1-next!=NULL)/*还没找到末尾,继续找 */p2=p1;p1=p1-next;p1-next=p0;p0-next=NULL;n=n+1;p1=head;p0=stu;for(i=1;inext;if(max-numberp1-number)k=max-number;max-number=p1-number;p1-number=k;/*交换前后结点中的学号值,使得学号大者移到后面的结点中*/strcpy(t,max-name);strcpy(max-name,p1-name);strcpy(p1-name,t);/*交换前后结点中的姓名,使之与学号相匹配*/*交换前后结点中的消费情况,使之与学号相匹配*/max=head;p1=head;/*重新使 max,p 指向链表头*/ 22 end2:printf(“now how many students are they:%d ge!n“,n);getch();return(head);/*=*/*=*/void print(score *head)score *p;if(head=NULL)printf(“nnobody information!n“);else 23 printf(“%dn“,n);printf(“-n“);printf(“|numbert|namet|consumet |n“);printf(“-n“);/*打印表格域*/p=head;doprintf(“|%dt|%st|%dtn“,p-number,p-name,p-xiaofei);printf(“-n“);/*打印表格域*/p=p-next;while (p!=NULL);/*打印完成了*/getch();/*= 24 =*/*=*/save(score *p1)FILE *fp;if(fp=fopen(“f:consume“,“wb“)=NULL)printf(“cant open this file!n“);return 0;elsewhile(p1!=NULL)fprintf(fp,“%d,%s,%dttt“,p1-number,p1-name,p1-xiaofei);/* printf(“file write errorn“);*/p1=p1-next; 25 printf(“file save complete!please enter return!n“);getch();fclose(fp);/*=*/*=主菜单=*/void menu() 26 system(“cls“);printf(“nnn“);printf(“tt-STUDENT CONSUME-n“);printf(“ttt0 exit n“);printf(“ttt1 creat n“);printf(“ttt2 load n“);printf(“ttt3 search n“);printf(“ttt4 delete n“);printf(“ttt5 add n“);printf(“ttt6 show n“);printf(“ttt7 save n“);printf(“tt-nn“);printf(“ttchoose(0-7):“);/*=主函数=*/main() 27 int num;score *head=0,*stu=0;menu();scanf(“%d“,while(1)switch(num)case 1: head=creat();break;case 2: head=load(head);break;case 3: head=search(head);break;case 4: head=del(head);break;case 5: head=add(hea

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论