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

下载本文档

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

文档简介

1、火车订票系统源码Sinelude <conioh Sinclude<stdio. h> ttinelude <stdlib. h>include <string h> int shoudsave=0;int countI=0/C0unt2=0, mark=0, mark: 1=0;/*定义存储火车信息的结构体-7struct traincharnum10 ;/* 列车号 *7char city10;/* 0 的城市*/char takeoff Time 10 ;/* 发车时间 */char receiveTime10; /*到达时间 */int pri

2、ce;/* 票价 */int bookNum ;广栗数*/;厂订票人的信息*/struct manchar numllO;/*ID*/char name10 ;/*龙名*7 int bookNum :/*需求的票数*/;/*定义火车信息链表的结点结构typedef struct nodestruct train data ;struct node * next:Node, *Link;厂定义订票人链表的结点结构*/typedef struct peoplestruct man data ;struct people*next:Jb ookMan/bookManL i nk;/*初始界面*7vo

3、id printinterface() puts (咏* * *u puts(H* Welcome to use the system of booking tickets *B);puts C*11 puts (H* You can choose theoperation:putsL*1:Insert a train information*u):puts(”*2:Inquire a train information*H):puts(”*3:Book a train ticket*):puts(”*4:Update the train information*):puts(”*5:Advi

4、ce to you about the train*n):puts(”*6:save information to file*n):puts(”*7:quit the system旳:厂添加一个火车信息-7void InsertTraininfo(Link linkhead) struct node *p,*rs*s;char num10;r = linkhead ;s = linkhead">next: while(r">next!=NULL) r=r>next;while(l)printf (please input the number of the

5、 train(0-return) n ; scanfs 舄 num): Vp (strcmp(num, *0 )=0)break;厂判断是否已经存在-7while (s)if(strcmp(s>data num, num)=0)printff* the train %s* has been born!n 舄 num);return ; s = s >next:p = (struct printf (slnputno de*)malloc(sizeof(struct no de); strcpy(p">datanum, num);will reach:11): sca

6、n f("弔s: p - >data.city);thecity where the trainprintf Clnputprintf Clnputprintf ("inputthethethetime which the traintime which the trainprice of ticket ::x):take off:"); scanf (s*, p">data takeoffTime); receive:1); scanfC's' “&pdata receiveTime);printf(Mlnput t

7、he number of booked tickets:"); scanf(%d"f &p-databookNum); p>next=NULL; r>next=p;r=P: shoudsave = 1;厂打印火车票信息>7void printTrainlnfo(struct node*p)puts(HnThe following is the record you want:*):print f (number of train: %snx, p">data .num);printf<K»city the train

8、 will reach: %sn* 'p'data.city); printf(u»the time the off: %snthe time the train reach: %sn*, p>datatakeoffTime, p-datareceiveTime);printf ('the price of the ticket: %dn p">data.price);printf (the number of booked tickets: %dn 舄 podata bookNum);struct node * LocatelfLink

9、 1, char findmess, char nximorcity )Node*r;if(strcmp(numorcity: "num')=0)r=l->next;while(r)if (strcmp (r>data num, findmess) =0) return r; r=r>next;else IT (strcmp(numorcityrcityM )=0)r=l->next;while(r)if(strcmp(r>data .city, fi ndmess)=0) return r; r=r>next;return 0;厂查询火车

10、信息沐/void QueryTrain(Link I)Node *p;int sei;char strl5, str210;if(!l->next) printf(HThere is not any record Is) ; return ;printf("Choose the way:n»l:according to the nximber of train;n»2:according scanf ( "%d” , &sel);train taketo the city:n"):if(sel=l)printff'Inpu

11、t the the number of train:;scan fstrl);p=Locatel (1, strl/num"):if(P)printTrainlnfo(p);elsemarkl=l; printf(nthe file can* t be found!*);else 讦(sel=2)pr intf(Input the city:");scanfstr2);p=Locatel (1, str2 "city");if(P)printTrainlnfo(p);elsemarkl=l;printf Cnthe file can* t be foun

12、d!11):/*订票子模块*/void BookTicket(Link 1, bookManLink k)Node*r10, *p;char ch, dem ; bookMan*v,*h ;int i=0, t=0;char str10, str110, str210;v=k;while(v->next!=NULL)v=v>next;printf ("Input the city you want to go: H): scanf&str);p=l">next: while(p!=NULL)if(strcmp(p->data city,str

13、)=0)rH=P : i卄:p=p->next;printf (Hnnthe number of record have %dn", i); for(t=0;t<i;t+)printTrainlnfo(r Lt);if(i=0)printf(XnXtXtXtSorrylCan1! find the train for you !rT):elseprintf (undo you want to book it?<l/0>n") ; scanf (*%dv , &ch);h=(bookMan*)malloc zeof(booklVlan); pr

14、intf(Hlnput your name:"); scanf("%s", &strl); strcpy(h">dataname,strl); printf(Hlnput your id:");bookNum:”);C语言编程火车订票系统源代码 scanf("%s",&str2); strcpy(h">data num, str2): printf Input your scanf(%cT,&dem);h >data bookNum . dem ; h>next=NU

15、LL;v - >next=h ;v=h ;printf(HnLucky!you have booked a ticket!"); getch(); shoudsave=l;bookMan*Locate2(bookManLink k, char findmess】)bookMan*r;r=k">next;while(r)if(strcmp(r>data num, finclmess)=O)mark=l;return r;r=r>next;return 0;厂修改火车信息沐/void VpdatelnfofLink I)Node*p;char findm

16、ess20, ch ;if(!l->next)printf (unthere isn't record for you to modify! nx) ; return ;elseQueryTrain(l); if(markl=0)printf (HnDo you want to modify it?nH) : getchar (.); scanf c 舄&ch):printf (Hnlnput the number of the train:1-); scanf (' %s" findmess); p=Locatel (1, findmess/1 num

17、-1);讦(P)printf r Input new number of train: ; scanf ('s',& p*>data .num); printf (Klnput new city the train will reach:u);scanfC %s',&p->data city);printf Clnput new time the train take off11):scanf C &p->data takeoffTime);printf Clnput new time the train reach:11);

18、sea nf %s&p*>data receiveTime);printf (Mlnput new price of the ticket:u);scanf 0 %d ' &p->data price);printf Clnput new number of people who have bookedticket O ;scanf (' %d &p->data bookNum); printf (Hnmodifying record is sucessful!nj; shoudsave=l;else printff'XtXtX

19、tcan't find the record! *):elsemark1=0;)/*系统给用户的提示信息*/void AdvicedTrains(Link I)Node*r; char str10;int mar=0;r%s舄str);r=l->next;printf (luput the city you want to go: a) ; scanfwhile(r)IT (strcmp(r>data city, str) =0&&r*">data. bookNum<200)mar=l;printf (xnyou can select

20、the following train !n):printf (/"XnXnplease select the fourth operation to book the ticket!n ");printTrainlnfo(r);r=r">next;if (mar=0)printf (Hntttyou can't book any ticket now!n*);/*保存火车信息void SaveTrainlnfo(Link I)FILE*fp ;Node*p;int count=0, flag . 1; fp=fopen (' c : tra

21、in. txt ' /wb*);if (fp=NVLL)printf (uthe file can't be opened!:x): return ;p=l->next;while(p)if(fwrite(p, sizeof(Node) 1, fp)=l)p=p->n ext;cou nt 卄;elseflag=0;break;if(flag)printf("the number of the record which have been saved is %dnHscount): shoudsave=0; fclose (fp):厂保存订票人的信息*/v

22、oid SaveBookmanlnfo(bookManLink k)FILE*fp;bookMan*p;int count=0, fbg . 1;fp=fopen rc:man - txtTwb “);if (fp=NULL)printf (Hthe file can* t be opened!11);return ;p=k_>next;while(p)if(fwrite(p, sizeof(bookMan), 1, fp)=l)p=p->n ext:cou nt+;elseflag二0 ;break;if (flag)printf Ct he nximber of the rec

23、ord which have been saved is %dn* * count) ; shoudsave=0;fclose(fp);int mainOFILE*fpl,*fp2;Node*p,*r; char chi,ch2 ;Link I;bookManLink k;bookMan*t, *h ;int sei;1=(Node*)malloc(sizeof(Node);1 >n ext=NULL;r=l;k=(bookMan*)malloc(sizeof(bookl/lan);konext=NVLL;h=k;fpl=fopen(' c: train. txt ; ab+&q

24、uot;);if(fpl=NULL)printff* can* t open the file!*): return 0;whiledfeof (fpl)p=(Node*)malloc(sizeof(Node);if (fread(p, sizeof(Node) 1, fpl)=l)p->next=NULL;r">next=p;r=P:cou ntl+;fclose(fpl);fp2=fopenCc: man. txt */ab+*);if(fp2=NULL)printff* can* t open the file!11): return 0;while(!feof(fp2)t= (bookMan*)m

温馨提示

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

评论

0/150

提交评论