




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、火車訂票系統(tǒng)源碼#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>int shoudsave=0 ;int count1=0,count2=0,mark=0,mark1=0 ;/*定義存儲(chǔ)火車信息的結(jié)構(gòu)體*/struct train char num10;/*列車號(hào)*/ char city10;/*目的城市*/ char takeoffTime10;/*發(fā)車時(shí)間*/ char receiveTime10;/*到達(dá)時(shí)間*/ int price;/*票價(jià)
2、*/ int bookNum ;/*票數(shù)*/;/*訂票人的信息*/struct man char num10;/*ID*/ char name10;/*姓名*/ int bookNum ;/*需求的票數(shù)*/;/*定義火車信息鏈表的結(jié)點(diǎn)結(jié)構(gòu)*/typedef struct node struct train data ; struct node * next ;Node,*Link ;/*定義訂票人鏈表的結(jié)點(diǎn)結(jié)構(gòu)*/typedef struct people struct man data ; struct people*next ;bookMan,*bookManLink ;/* 初始界面*/
3、void printInterface() puts("*"); puts("* Welcome to use the system of booking tickets *"); puts("*"); puts("* You can choose the operation: *");1 / 12 puts("* 1:Insert a train information *"); puts("* 2:Inquire a train information *"); puts
4、("* 3:Book a train ticket *"); puts("* 4:Update the train information *"); puts("* 5:Advice to you about the train *"); puts("* 6:save information to file *"); puts("* 7:quit the system *"); puts("*");/*添加一個(gè)火車信息*/void InsertTraininfo(Link l
5、inkhead) struct node *p,*r,*s ; char num10; r = linkhead ; s = linkhead->next ; while(r->next!=NULL) r=r->next ; while(1) printf("please input the number of the train(0-return)"); scanf("%s",num); if(strcmp(num,"0")=0) break ; /*判斷是否已經(jīng)存在*/ while(s) if(strcmp(s-
6、>data.num,num)=0) printf("the train '%s'has been born!n",num); return ; s = s->next ; p = (struct node*)malloc(sizeof(struct node); strcpy(p->data.num,num); printf("Input the city where the train will reach:"); scanf("%s",p->data.city); printf("
7、Input the time which the train take off:"); scanf("%s",p->data.takeoffTime); printf("Input the time which the train receive:"); scanf("%s",&p->data.receiveTime); printf("Input the price of ticket:"); scanf("%d",&p->data.price);
8、printf("Input the number of booked tickets:"); scanf("%d",&p->data.bookNum); p->next=NULL ; r->next=p ; r=p ; shoudsave = 1 ; /*打印火車票信息*/void printTrainInfo(struct node*p) puts("nThe following is the record you want:"); printf(">>number of train:
9、 %sn",p->data.num); printf(">>city the train will reach: %sn",p->data.city); printf(">>the time the train take off: %snthe time the train reach: %sn",p->data.takeoffTime,p->data.receiveTime); printf(">>the price of the ticket: %dn",p-&
10、gt;data.price); printf(">>the number of booked tickets: %dn",p->data.bookNum);struct node * Locate1(Link l,char findmess,char numorcity) 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 if
11、(strcmp(numorcity,"city")=0) r=l->next ; while(r) if(strcmp(r->data.city,findmess)=0) return r ; r=r->next ; return 0 ;/*查詢火車信息*/void QueryTrain(Link l) Node *p ; int sel ; char str15,str210; if(!l->next) printf("There is not any record !"); return ; printf("Choo
12、se the way:n>>1:according to the number of train;n>>2:according to the city:n"); scanf("%d",&sel); if(sel=1) printf("Input the the number of train:"); scanf("%s",str1); p=Locate1(l,str1,"num"); if(p) printTrainInfo(p); else mark1=1 ; print
13、f("nthe file can't be found!"); else if(sel=2) printf("Input the city:"); scanf("%s",str2); p=Locate1(l,str2,"city"); if(p) printTrainInfo(p); else mark1=1 ; printf("nthe file can't be found!"); /*訂票子模塊*/void BookTicket(Link l,bookManLink k)
14、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: "); scanf("%s",&str); p=l->next ; while(p!=NULL) if(strcmp(p->data.city,str)=0) ri=p ; i+; p=p->next
15、 ; printf("nnthe number of record have %dn",i); for(t=0;t<i;t+) printTrainInfo(rt); if(i=0) printf("ntttSorry!Can't find the train for you!n"); else printf("ndo you want to book it?<1/0>n"); scanf("%d",&ch); if(ch = 1) h=(bookMan*)malloc(sizeo
16、f(bookMan); printf("Input your name: "); scanf("%s",&str1); strcpy(h->,str1); printf("Input your id: "); scanf("%s",&str2); strcpy(h->data.num,str2); printf("Input your bookNum: "); scanf("%d",&dem); h->data.bo
17、okNum=dem ; h->next=NULL ; v->next=h ; v=h ; printf("nLucky!you have booked a ticket!"); getch(); shoudsave=1 ; bookMan*Locate2(bookManLink k,char findmess) bookMan*r ; r=k->next ; while(r) if(strcmp(r->data.num,findmess)=0) mark=1 ; return r ; r=r->next ; return 0 ;/*修改火車信息
18、*/void UpdateInfo(Link l) Node*p ; char findmess20,ch ; if(!l->next) printf("nthere isn't record for you to modify!n"); return ; else QueryTrain(l); if(mark1=0) printf("nDo you want to modify it?n"); getchar(); scanf("%c",&ch); if(ch='y'); printf(&quo
19、t;nInput the number of the train:"); scanf("%s",findmess); p=Locate1(l,findmess,"num"); if(p) printf("Input new number of train:"); scanf("%s",&p->data.num); printf("Input new city the train will reach:"); scanf("%s",&p->
20、data.city); printf("Input new time the train take off"); scanf("%s",&p->data.takeoffTime); printf("Input new time the train reach:"); scanf("%s",&p->data.receiveTime); printf("Input new price of the ticket:"); scanf("%d",&
21、p->data.price); printf("Input new number of people who have booked ticket:"); scanf("%d",&p->data.bookNum); printf("nmodifying record is sucessful!n"); shoudsave=1 ; else printf("tttcan't find the record!"); else mark1=0 ; /*系統(tǒng)給用戶的提示信息*/void Advi
22、cedTrains(Link l) Node*r ; char str10; int mar=0 ; r=l->next ; printf("Iuput the city you want to go: "); scanf("%s",str); while(r) if(strcmp(r->data.city,str)=0&&r->data.bookNum<200) mar=1 ; printf("nyou can select the following train!n"); printf(&q
23、uot;nnplease select the fourth operation to book the ticket!n"); printTrainInfo(r); r=r->next ; if(mar=0) printf("ntttyou can't book any ticket now!n"); /*保存火車信息*/void SaveTrainInfo(Link l) FILE*fp ; Node*p ; int count=0,flag=1 ; fp=fopen("c:train.txt","wb")
24、; if(fp=NULL) printf("the file can't be opened!"); return ; p=l->next ; while(p) if(fwrite(p,sizeof(Node),1,fp)=1) p=p->next ; count+; else flag=0 ; break ; if(flag) printf("the number of the record which have been saved is %dn",count); shoudsave=0 ; fclose(fp);/*保存訂票人的
25、信息*/void SaveBookmanInfo(bookManLink k) FILE*fp ; bookMan*p ; int count=0,flag=1 ; fp=fopen("c:man.txt","wb"); if(fp=NULL) printf("the file can't be opened!"); return ; p=k->next ; while(p) if(fwrite(p,sizeof(bookMan),1,fp)=1) p=p->next ; count+; else flag=0 ;
26、 break ; if(flag) printf("the number of the record which have been saved is %dn",count); shoudsave=0 ; fclose(fp);int main() FILE*fp1,*fp2 ; Node*p,*r ; char ch1,ch2 ; Link l ; bookManLink k ; bookMan*t,*h ; int sel ; l=(Node*)malloc(sizeof(Node); l->next=NULL ; r=l ; k=(bookMan*)malloc
27、(sizeof(bookMan); k->next=NULL ; h=k ; fp1=fopen("c:train.txt","ab+"); if(fp1=NULL) printf("can't open the file!"); return 0 ; while(!feof(fp1) p=(Node*)malloc(sizeof(Node); if(fread(p,sizeof(Node),1,fp1)=1) p->next=NULL ; r->next=p ; r=p ; count1+; fclose(fp1); fp2=fopen("c:man.txt","ab+"); if(fp2=NULL) printf("can't open the file!"); return 0 ; whi
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 內(nèi)審員考試試題及答案 (三)
- 海洋數(shù)字金融服務(wù)創(chuàng)新
- 2025年上海松江區(qū)天馬山學(xué)校招聘教師考試筆試試題(含答案)
- 老班長(zhǎng)介紹課件
- 老年疼痛患者護(hù)理課件
- 老年護(hù)理課件模板
- 老年護(hù)理圖文課件
- 老年人心理健康咨詢課件
- 老師的視頻課件制作
- 《建筑項(xiàng)目合同約定場(chǎng)地估值爭(zhēng)議處理協(xié)議》
- 工程總承包管理制度
- 2025年云南新華印刷五廠有限責(zé)任公司招聘筆試參考題庫(kù)含答案解析
- 汽車實(shí)訓(xùn)室安全課件
- 臨時(shí)施工出入口交通疏導(dǎo)方案
- 《OPPLE歐普照明》課件
- 國(guó)家開(kāi)放大學(xué)電大??啤督ㄖこ添?xiàng)目管理》期末試題及答案
- 醫(yī)療設(shè)備器材供貨安裝、調(diào)試及售后服務(wù)方案
- 部編版語(yǔ)文三年級(jí)上冊(cè)第四單元教材解讀大單元集體備課
- 10kV小區(qū)供配電設(shè)計(jì)、采購(gòu)、施工EPC 投標(biāo)方案(技術(shù)方案)
- 2024-2025學(xué)年初中物理八年級(jí)下冊(cè)蘇科版(2024)教學(xué)設(shè)計(jì)合集
- 中外廣告史(第三版) 課件全套 何玉杰 第0-11章 緒論、中國(guó)古代廣告的發(fā)展- 日本廣告的發(fā)展
評(píng)論
0/150
提交評(píng)論