C语言编程火车订票系统源代码_第1页
C语言编程火车订票系统源代码_第2页
C语言编程火车订票系统源代码_第3页
C语言编程火车订票系统源代码_第4页
C语言编程火车订票系统源代码_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

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

文档简介

1、C语言编程火车订票系统源代码火车订票系统源码#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>int shoudsave=0;int countl=0/count2=0,mark=0,markl=0;/*定义存储火车信息的结构体*/struct train(charnum10;/* 列车号*/char city10;/* 目的城市*/char takeoff!ime10;/* 发车时间*/char receiveTime10;/*到达时间*/int

2、price;/* 票价*/ int bookNum ;/*票数*/);/*订票人的信息*/struct man(char num10;/*ID*/char name10;/*姓名*/ int bookNum ;/*需求的票数*/);/*定义火车信息链表的结点结构*/typedef struct node(struct train data ;struct node * next;Nodez*Link;/*定义订票人链表的结点结构*/typedef struct people(struct man data ;struct people*next;JbookMan/bookManLink;/*初

3、始界面*/void printlnterface()(puts(H* * *11), puts(H* Welcome to use the system of booking tickets *n);putsf11*11), puts(H* You can choose the operation:*n);puts("*l:lnsert a train information*”);puts("*2:lnquire a train information*“);puts("*3:Book a train ticket*H);puts("*4:llpdat

4、e the train information*”);puts("*5:Advice to you about the train*”);puts("*6:save information to file*”);puts("*7:quit the system*");P uts( *”);)/*添加一个火车信息*/void lnsertTraininfo(Link linkhead)struct node *p,*r,*s; char num10;r = linkhead ;s = linkhead->next; while(r->next!

5、=NULL)r=r->next;while(l)(printf(Hplease input the number of the train(O-return)u);scanf("%snum);if(strcmp(num,lO,)=O)break;/*判断是否已经存在*/while(s)(if(strcmp(s->data.num,num)=O)(printf(Hthe train *%s'has been born!n,/num); return;)s = s->next;)p = (struct node*)malloc(sizeof(struct nod

6、e);strcpy(p->data.num,num);printf(Hlnput the city where the train will reach:11);scanf(,%s,p->data.city);printf(nlnput the time which the train take off:11);scanf(,%s,p->data.takeoffTime);printf(Hlnput the time which the train receive:11);scanf(,%s,&p->data.receiveTime);printf(Hlnput

7、 the price of ticket:");scanf(,%d,&p->data.price);printf(Hlnput the number of booked tickets:11);scanf(,%d,&p->data.bookNum);p->next=NULL;r->next=p;r=P;shoudsave = 1;)/*打印火车票信息*/void printTrainlnfo(struct node*p) (puts(HnThe following is the record you want:");printf(H&

8、#187;number of train: %snu,p->data.num);printf(H»city the train will reach: %sn,p->data.city);printf(u»the time the train take off: %snthe time the trainreach: %snI,/p->data.takeoffTime,p->data.receiveTime);printf(H»the price of the ticket: %dn,/p->data.price);printf(u&

9、#187;the number of booked tickets: %dn,I,p->data.bookNum); )struct node * LocatelfLink l,char findmess,char numorcity) (Node*r;if(strcmp(numorcity,numI,)=0)(r=l->next;while(r) (if(strcmp(r->data.num,findmess)=O)return r;r=r->next;)else if(strcmp(numorcity/,city,)=0)(r=l->next;while(r)

10、 (if(strcmp(r->data.city/findmess)=O)return r;r=r->next;)return 0;/*查询火车信息*/void QueryTrain(Link I)(Node *p; int sei; char strl5,str210; if(!l->next) (printf(HThere is not any record !"); return ;)printf("Choose the way:n»l:according to the number of train;n»2:according

11、to the city:n");scanf("%d"z&sel);if(sel=l)(printff'lnput the the number of train:");scanf(”s,strl);p=Locatel(l,strl/,num"); if(P) (printTrainlnfo(p);)else(markl=l; printf("nthe file can't be found!");)else if(sel=2)(printf("lnputthe city:");sc

12、anf("%s”,str2);p=Locatel(l,str2/"city");if(P)( printTrainlnfo(p);)else(markl=l;printf("nthe file can't be found!"); )/*订票子模块*/void BookTicket(Link l,bookManLink k) (Node*r10L*p;char ch,dem ;bookMan*v,*h ;int i=O,t=O;char str10,strl10/str210;v=k;while(v->next!=NULL)v=v

13、->next;printf(Hlnput the city you want to go:");scanf("%s",&str);p=l->next;while(p!=NULL)(if(strcmp(p->data.city,str)=O)(ri=P;i+;)p=p->next;)printf(Hnnthe number of record have %dnM,i);for(t=0;t<i;t+)printTrainlnfo(rt);if(i=O)printf(I,ntttSorry!Can,t find the train

14、for you!nM); else(printf(undo you want to book it?<l/O>nM);scanf(”d,&ch);if(ch = 1) (h=(bookMan*)malloc(sizeof(bookMan);printf(Hlnput your name:");scanf("%s",&strl);strcpy(h->/strl);printf(Hlnput your id:");scanf("%s",&str2);strcpy(h->da

15、ta.num,str2);printf(Hlnput your bookNum: n);scanf(,%d,&dem);h->data.bookNum=dem ;h->next=NULL;v->next=h ;v=h ;printf(HnLucky!you have booked a ticket!11);getch();shoudsave=l;)bookMan*Locate2(bookManLink k,char findmess)(bookMan*r;r=k->next;while(r)(if(strcmp(r->data.num/findmess)=

16、O)(mark=l;return r;)r=r->next;)return 0;)/*修改火车信息*/void UpdatelnfofLink I)(Node*p;char findmess20,ch ;if(!l->next)(printf(unthere isn't record for you to modify!nu); return ;)else(QueryTrain(l);if(markl=O)printf("nDo you want to modify it?nH);getchar();scanfCW&ch);if(ch=,y');(

17、printf(Hnlnput the number of the train:11);scanf(,%s,findmess);p=Locatel(l,findmessJnum");if(P)(printf(Hlnput new number of train:11);scanf(,%s,/&p->data.num);printf(Hlnput new city the train will reach:11);scanf(,%s,/&p->data.city);printf(nlnput new time the train take off11);sca

18、nf(,%s,/&p->data.takeoffTime);printf(Hlnput new time the train reach:11);scanf(,%s,/&p->data.receiveTime);printf(Hlnput new price of the ticket:11); scanf(,%dl,&p->data.price);printf(Hlnput new number of people who have booked ticket:");scanf(,%dl,/&p->data.bookNum);

19、printf(Hnmodifying record is sucessful!nH); shoudsave=l;)elseprintff'XtXtXtcan't find the record!");)elsemarkl=O;)/*系统给用户的提示信息*/void AdvicedTrains(Link I)(Node*r;char str10;int mar=O;r=l->next;printf(nluput the city you want to go:");scanf("%s",str);while(r)if(strcmp(r

20、->data.city,str)=0&&r->data.bookNum<200) (mar=l;printf(Hnyou can select the following train !nM);printf(Hnnplease select the fourth operation to book the ticket!nn); printTrainlnfo(r);)r=r->next;)if(mar=O)printf(Hntttyou can't book any ticket now!n");)/*保存火车信息*/void Save

21、Trainlnfo(Link I)(FILE*fp ;Node*p;int count=0,flag=l;fp=fopen(,c:train.txt,/,wb,');if(fp=NULL)(printf(uthe file can't be opened!11);return ;)p=l->next;while(p)(if(fwrite(p,sizeof(Node)/l,fp)=l)(p=p->next;count+;)else(flag=O;break;)if(flag)printf(uthe number of the record which have bee

22、n saved is %dnn,count);shoudsave=0;)fclose(fp);)/*保存订票人的信息*/void SaveBookmanlnfo(bookManLink k) (FILE*fp;bookMan*p;int count=0,flag=l;fp=fopenduWman.txtVwb");if(fp=NULL)(printf(Hthe file can't be opened!11);return ;)p=k->next;while(p)(if(fwrite(p,sizeof(bookMan),l,fp)=l)(p=p->next;cou

23、nt+;) else(flag=O;break;)if(flag)(printf(uthe number of the record which have been saved is %dnn,count); shoudsave=0;)fclose(fp);)int main()(FILE*fpl,*fp2;Node*p,*r;char chl,ch2 ;Link I;bookManLink k;bookMan*t,*h ;int sei;l=(Node*)malloc(sizeof(Node);l->next=NULL;r=l;k=(bookMan*)malloc(sizeof(boo

24、kl/lan);k->next=NULL;h=k;fpl=fopen("c:train.txt"z"ab+");if(fpl=NULL)(printff'can't open the file!11);return 0;)while(!feof(fpl)(p=(Node*)malloc(sizeof(Node); if(fread(p,sizeof(Node)/l,fpl)=l) (p->next=NULL;r->next=p;r=P; countl+;)fclose(fpl);fp2=fopen("c:man.txt"/"ab+");if(fp2=NULL)(printff'can't open the file!11);return 0;)while(!feof(fp2)(t=(boo

温馨提示

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

评论

0/150

提交评论