版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.火车订票系统源码#include #include #include #include int shoudsave=0 ;int count1=0,count2=0,mark=0,mark1=0 ;/*定义存储火车信息的结构体*/struct train char num10;/*列车号*/ char city10;/*目的城市*/ char takeoffTime10;/*发车时间*/ char receiveTime10;/*到达时间*/ int price;/*票价*/ int bookNum ;/*票数*/;/*订票人的信息*/struct man char num10;/*ID*/
2、 char name10;/*姓名*/ int bookNum ;/*需求的票数*/;/*定义火车信息链表的结点结构*/typedef struct node struct train data ; struct node * next ;Node,*Link ;/*定义订票人链表的结点结构*/typedef struct people struct man data ; struct people*next ;bookMan,*bookManLink ;/* 初始界面*/void printInterface() puts(*); puts(* Welcome to use the syst
3、em of booking tickets *); puts(*); puts(* You can choose the operation: *); puts(* 1:Insert a train information *); puts(* 2:Inquire a train information *); puts(* 3:Book a train ticket *); puts(* 4:Update the train information *); puts(* 5:Advice to you about the train *); puts(* 6:save information
4、 to file *); puts(* 7:quit the system *); puts(*);/*添加一个火车信息*/void InsertTraininfo(Link linkhead) 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) br
5、eak ; /*判断是否已经存在*/ while(s) if(strcmp(s-data.num,num)=0) printf(the train %shas 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(Input the time which the tra
6、in 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); printf(Input the number of booked tickets:); scanf(%d,&p-data.bookNum); p-next=NULL ; r-next=p ; r=p ; shoudsave =
7、 1 ; /*打印火车票信息*/void printTrainInfo(struct node*p) puts(nThe following is the record you want:); printf(number of train: %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); p
8、rintf(the price of the ticket: %dn,p-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(strcmp(numorc
9、ity,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(Choose the way:n1:according to the number of train;n2:according
10、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 ; printf(nthe t be found!); else if(sel=2) printf(Input the city:); scanf(%s,str2); p=Locate1(l,str2,city); if(p) printTrainInfo(p); else mar
11、k1=1 ; printf(nthe t be found!); /*订票子模块*/void BookTicket(Link l,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: ); scanf(%s,&str); p=l-next ; while(p!=NULL) if(strcmp(p-data.
12、city,str)=0) 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(ntttSorry!Cant find the train for you!n); else printf(ndo you want to book it?n); scanf(%d,&ch); if(ch = 1) h=(bookMan*)malloc(sizeof(bookMan); printf(Input your name: ); s
13、canf(%s,&str1); strcpy(,str1); printf(Input your id: ); scanf(%s,&str2); strcpy(h-data.num,str2); printf(Input your bookNum: ); scanf(%d,&dem); h-data.bookNum=dem ; h-next=NULL ; v-next=h ; v=h ; printf(nLucky!you have booked a ticket!); getch(); shoudsave=1 ; bookMan*Locate2(bookManLink
14、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 ;/*修改火车信息*/void UpdateInfo(Link l) Node*p ; char findmess20,ch ; if(!l-next) printf(nthere isnt record for you to modify!n); return ; else QueryTrain(l); if(mark1=0) printf(nDo
15、you want to modify it?n); getchar(); scanf(%c,&ch); if(ch=y); printf(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-data.city); printf(Input ne
16、w 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,&p-data.price); printf(Input new number of people who have booked ticket:); scanf(%d,&p-data.bookNum); printf(nmodifying
17、 record is sucessful!n); shoudsave=1 ; else printf(tttcant find the record!); else mark1=0 ; /*系统给用户的提示信息*/void AdvicedTrains(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.bookNumnext ; if(mar=
18、0) printf(ntttyou cant book any ticket now!n); /*保存火车信息*/void SaveTrainInfo(Link l) ; Node*p ; int count=0,flag=1 ; fp=fopen(c:train.txt,wb); if(fp=NULL) printf(the 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(
19、the number of the record which have been saved is %dn,count); shoudsave=0 ; fclose(fp);/*保存订票人的信息*/void SaveBookmanInfo(bookManLink k) ; bookMan*p ; int count=0,flag=1 ; fp=fopen(c:man.txt,wb); if(fp=NULL) printf(the t be opened!); return ; p=k-next ; while(p) if(fwrite(p,sizeof(bookMan),1,fp)=1) p=
20、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);int main() ,*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*)
21、malloc(sizeof(bookMan); k-next=NULL ; h=k ; fp1=fopen(c:train.txt,ab+); if(fp1=NULL) printf(cant 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(cant open the file!); return 0 ; while(!feof(fp2) t=(bookMan*)malloc(sizeof(bookMan); if(fread(t,s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年大学四年级(食品科学与工程)食品机械与设备试题及答案
- 2026年中医推拿按摩师(理论知识)试题及答案
- 2025年大学速度滑冰团体追逐运动与管理(团体追逐技术)试题及答案
- 2025年大学大四(土木工程)工程项目管理综合测试卷
- 2026年中医护理(中医护理技术)综合测试题及答案
- 深度解析(2026)《GBT 18115.1-2020稀土金属及其氧化物中稀土杂质化学分析方法 第1部分:镧中铈、镨、钕、钐、铕、钆、铽、镝、钬、铒、铥、镱、镥和钇量的测定》
- 深度解析(2026)《GBT 17980.106-2004农药 田间药效试验准则(二) 第106部分杀菌剂防治玉米丝黑穗病》
- 深度解析(2026)《GBT 17963-2000信息技术 开放系统互连 网络层安全协议》
- 深度解析(2026)《GBT 17721-1999金属覆盖层 孔隙率试验 铁试剂试验》
- 深度解析(2026)《GBT 17564.6-2021电气元器件的标准数据元素类型和相关分类模式 第6部分:IEC公共数据字典(IEC CDD)质量指南》
- 2026年采购部年度工作计划及管理方案
- 餐饮原材料合同范本
- 足浴店加盟店合同范本2025年版合同
- 北京朝阳区六里屯街道办事处招聘18名城市协管员考试笔试备考题库及答案解析
- 2025年科研伦理与学术规范期末考试及参考答案
- 货款尾款结算协议书
- 村会计笔试试题及答案
- 2026年江西省铁路航空投资集团校园招聘(24人)笔试考试参考题库及答案解析
- 2025年徐州市教育局直属学校招聘真题
- 消防设施共用责任划分协议书范本
- 杜国楹小罐茶的创业讲稿
评论
0/150
提交评论