C語言編程---火車訂票系統(tǒng)源代碼之歐陽引擎創(chuàng)編_第1頁
C語言編程---火車訂票系統(tǒng)源代碼之歐陽引擎創(chuàng)編_第2頁
C語言編程---火車訂票系統(tǒng)源代碼之歐陽引擎創(chuàng)編_第3頁
C語言編程---火車訂票系統(tǒng)源代碼之歐陽引擎創(chuàng)編_第4頁
C語言編程---火車訂票系統(tǒng)源代碼之歐陽引擎創(chuàng)編_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、火車訂票系統(tǒng)源碼歐陽引擎(2021.01.01)#include #include #include #include intshoudsave=0 ;int count 1 =0,count2=0,mark=0,mark 1 =0 ;/*定義存儲火車信息的結(jié)構(gòu)體*/struct trainchar num10;/* 列車號 */char city 10 ;/* 目的城市 */char takeoffTime 10 ;/* 發(fā)車時間*/char receiveTime10;/* 到達時間*/int price;/*票價*/intbookNum ;/*票數(shù)*/;/*訂票人的信息*/struct

2、mancharnum 10 ;/* ID*/char name10;/* 姓名 */ intbookNum ;/*需求的票數(shù)*/ ;八定義火車信息鏈表的結(jié)點結(jié)構(gòu)*/typedefstruct nodestruct train data ;struct node * next;Node,*Link;八定義訂票人鏈表的結(jié)點結(jié)構(gòu)勺typedefstruct peoplestruct man data ;struct people*next;bookMan,*bookManLink ;/*初始界面*/voidprintlnterface()11 士 士士 丄士士J. 士士% 土 士 士士 士*“);#

3、r%彳、#%puts(M* Welcome to use the system of booking tickets *n);11土土土f t#T%彳、彳.彳彳、V 彳、*)puts(*You can choose the operation:*“);puts(”*l:Insert a train information*“);puts(H*2:Inquire a train information紗);putsC*3:Book a train ticket*“);puts(*4:Update the train information*”);putsC*5:Advice to you abo

4、ut the train絆);puts(*6:save information to file*”);puts(H*7:quit the system*”);Z 1 | 士 士士士 %t 土 %t+%f 士 士 士 %t 土 士 士 + 士 %f “ 丄 士 ”士彳.r彳.彳.彳.*r八添加一個火車信息*/voidInsertTraininfo(Link linkhead) struct node *p,*r,*s ;charnum10;r = linkhead ;s = linkhead-next;while(r-next! =NULL)r=r-next;while(l) printf(Hp

5、lease input the number of the train(0-return)H); scanf(%s,num);if(strcmp(num,n0,)=0)break ;/*判斷杲否已經(jīng)存在*/while(s)if(strcmp(s-data.num,num)=O)printf(Hthe train %shas been born!n,num);return ;s = s-next;p = (struct node*)malloc(sizeof(struct node); strcpy(p-data.num,num);printf(HInput the city where the

6、 train will reach:11); scanf(H%sM,p-data.city);printf(HInput the time which the train take off:”); scanf(n%s,p-data.takeoffTime);printf(HInput the time which the train receive:H);scanf(H%sH,&p-data.receiveTime);printf(HInput the price of ticket:”);scanf(%d, &p-data.price);printf(HInput the number of

7、 booked tickets:11);scanf(%d,&p-data.bookNum);p-next=NULL ;r-next=p ;r=p ;shoudsave = 1 ;/*打印火車票信息*/voidprintTrainlnfo(struct node*p)puts(HnThe following is the record you want:11);printf(Hnumber of train: %snH,p-data.num);printf(Hcity the train will reach: %snM,p-data.city);printf(Hthe time the tra

8、in take off: %snthe time the trainreach: %snM,p-data.takeoffTime,p-data.receiveTime);printf(Hthe price of the ticket: %dnn,p-data.price);printf(Hthe number of booked tickets: %dnM,p-data.bookNum); struct node * Locate 1 (Link l,charfindmess,char numorcity) Node*r ;if(strcmp(numorcity,Hnum)=0)r=l-nex

9、t;while(r)if(strcmp(r-data.num,findmess)=O)return r ;r=r-next;else if(strcmp(numorcity/rcityM)=0)r=l-next;while(r)if(strcmp(r-data.city,findmess)=O)return r ;r=r-next;return 0 ;/*查詢火車信息*/voidQueryTrain(Link 1)Node *p ;intsel ;char strl5,str210;if(!l-next)printf(There is not any record !);return ;pri

10、ntf(Choose the way:n 1:according to the number of train;n2:according to the city:n);scanf(“d”,&sel);if(sel=l)printfCInput the the number of train:);scanf(%s,strl);p=Locate 1 (hstrl/numH);if(p)printTrainlnfo(p);elsemark 1 = 1 ;printf(Hnthe file cant be found!);else if(sel=2)printfCInput the city:1);s

11、canf(%s,str2);p=Locate 1 (l,str2,”city); if(p)printTrainlnfo(p);elsemark 1 = 1 ;printf(nthe file cant be found!);/*訂票子模塊*/voidBookTicket(Link l,bookManLink k)Node*r10,*p ;charch.dem ;bookMan*v,*h ;int i=0,t=0 ;charstr 10,str 1 10,str2l 0;v=k ;while(v-next!=NULL)v=v-next;printf(HInput the city you wa

12、nt to go:);scanf(%s,&str);p=l-next;while(p!=NULL)ri=P ;i+;p=p-next;printf(nnthe number of record have %dn,i);for(t=0;ti;t+)printTrainInfo(rt);if(i=0)printf(HntttSon-y!Cant find the train for you!n);elseprintf(ndo you want to book it?n); scanf(H%dn,&ch);if(ch = 1)h=(bookMan*)malloc(sizeof(bookMan);pr

13、intf(HInput your name: ”); scanf(n%s,&strl); strcpy(,strl); printf(Input your id:);scanf(H%sH,&str2);strcpy(h-data.num,str2);printf(HInput your bookNum: M);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 ;b

14、ookMan*Locate2(bookManLinkk,charfindmess)bookMan*r;r=k-next;while(r)mark=l ;return r ;)r=r-next;return 0 ;)/*修改火車信息*/voidUpdateInfo(Link 1)Node*p ;charfindmess20 ,ch ;if(!l-next)printf(Hnthere isrft record for you to modify!n“); return ;elseQueryTrain(l);if(markl=0)printf(HnDo you want to modify it?

15、nH);getchar();scanf(%c,&ch);if(ch=y);printf(HnInput the number of the train:11);scanf(M %s*,findmess);p=Locate 1 (1,findmess,nnumH);if(p)printf(HInput new number of train:11);scanf(H%sH,&p-data.num);printf(HInput new city the train will reach:M);scanf(%s”,&p-data.city);printf(HInput new time the tra

16、in take off); scanf(,%s,&p-data.takeoffTime);printf(HInput new time the train reach:n);scanf(H%sH,&p-data.receiveTime);printf(HInput new price of the ticket:11);scanf(%d,&p-data.price);printf(HInput new number of people who have booked ticket:11); printf(Hnmodifying record is sucessful!nH); shoudsav

17、e=l ;)elseprintf(Htttcant find the record!);)elsemark 1=0 ;/客系統(tǒng)給用戶的提示信息*/voidAdvicedTrains(Link 1)Node*r ;charstr10;int mar=0 ;r=l-next;printf(HIuput the city you want to go:);scanf(n%s,str);while(r)if(strcmp(r-data.city,str)=0&r-data.bookNumnext;if(mar=0)printf(ntttyou cant book any ticket now!nn);

18、/*保存火車信息*/voidSaveTrainInfo(Link 1)FILE*fp ;Node*p ;int count=0,flag=l ;fp=fopen(,c:train.txt,wb,);if(fp=NULL)return ;p=l-next;while(p)if(fwrite(p,sizeof(Node), 1 ,fp)= 1)p=p-next;count+;elseflag=0 ;break ;iftflag)printf(Hthe number of the record which have been saved is %dn,count);shoudsave=0 ;fclo

19、se(fp);/*保存訂票人的信息*/voidSaveBookmanInfo(bookManLink k)FILE*fp ;bookMan*p ;int count=0,flag=l ;fp二fopen(c:man.txt”,wb);if(fp=NULL)printfCthe file cant be opened!);return ;p=k-next;while(p)if(fwrite(p,sizeof(bookMan), 1 ,fp)= 1)p=p-next;count+;elseflag=0 ;break ;if(flag)printf(the number of the record

20、which have been saved is %dn,count);shoudsave=0 ;fclose(fp);)int main()FILE*fpl,*fp2;Node*p,*r;char chl,ch2 ;Link 1 ;bookManLink k ;bookMan*t,*h ;intsel ;l=(Node*)malloc(sizeof(Node);l-next=NULL ;r=l ;k=(bookMan*)malloc(sizeof(bookMan); k-next=NULL ;h=k ;fpl =fopen(c:train.txt,ab+);if(fpl=NULL)print

21、fCcant open the file!);return 0 ;while(!feof(fpl)p=(Node*)malloc(sizeof(Node);if(fread(p,sizeof(Node), 1 ,fpl)= 1)p-next=NULL ;r-next=p ;r 二p;count 1+;fclose(fpl);fp2=fopen(,c:man.txt,ab+);if(fp2=NULL)printf(cant open the file!1);return 0 ;while(!feof(fp2)t=(bookMan*)malloc(sizeof(bookMan);if(fread(t,size

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論