ImageVerifierCode 换一换
格式:DOC , 页数:12 ,大小:25.18KB ,
资源ID:10190548      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-10190548.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言编程---火车订票系统源代码.doc)为本站会员(精品资料)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

C语言编程---火车订票系统源代码.doc

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*/char n

2、ame10;/*姓名*/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 system of boo

3、king 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)brea

5、k ;/*判断是否已经存在*/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 train tak

6、e off:“);scanf(“%s“,p-data.takeoffTime);printf(“Input the time which the train receive:“);scanf(“%s“,printf(“Input the price of ticket:“);scanf(“%d“,printf(“Input the number of booked tickets:“);scanf(“%d“,p-next=NULL ;r-next=p ;r=p ;shoudsave = 1 ;/*打印火车票信息*/void printTrainInfo(struct node*p)puts(“

7、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);printf(“the price of the ticket: %dn“,p-data.price);pr

8、intf(“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(numorcity,“city“)=0)r=l-next ;while(r)if(strcmp(r-data.city,fi

9、ndmess)=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 to the city:n“);scanf(“%d“,if(sel=1)printf(“Input the the number

10、 of train:“);scanf(“%s“,str1);p=Locate1(l,str1,“num“);if(p)printTrainInfo(p);else mark1=1 ;printf(“nthe file cant 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 cant be found!“);/*订票子模块*/void BookTi

11、cket(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“,p=l-next ;while(p!=NULL)if(strcmp(p-data.city,str)=0)ri=p ;i+;p=p-next ;printf(“nnthe number of record have %

12、dn“,i);for(t=0;tn“);scanf(“%d“,if(ch = 1)h=(bookMan*)malloc(sizeof(bookMan);printf(“Input your name: “);scanf(“%s“,strcpy(h-data.name,str1);printf(“Input your id: “);scanf(“%s“,strcpy(h-data.num,str2);printf(“Input your bookNum: “);scanf(“%d“,h-data.bookNum=dem ;h-next=NULL ;v-next=h ;v=h ;printf(“n

13、Lucky!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 ;/*修改火车信息*/void UpdateInfo(Link l)Node*p ;char findmess20,ch ;if(!l-next)printf(“nthere isnt record fo

14、r you to modify!n“);return ;else QueryTrain(l);if(mark1=0)printf(“nDo you want to modify it?n“);getchar();scanf(“%c“,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“,printf(“Input new city the tra

15、in will reach:“);scanf(“%s“,printf(“Input new time the train take off“);scanf(“%s“,printf(“Input new time the train reach:“);scanf(“%s“,printf(“Input new price of the ticket:“);scanf(“%d“,printf(“Input new number of people who have booked ticket:“);scanf(“%d“,printf(“nmodifying record is sucessful!n

16、“);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)=0if(mar=0)printf(“ntttyou cant book any ticket now!n“);/*

17、保存火车信息*/void SaveTrainInfo(Link l)FILE*fp ;Node*p ;int count=0,flag=1 ;fp=fopen(“c:train.txt“,“wb“);if(fp=NULL)printf(“the file cant 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 s

18、aved is %dn“,count);shoudsave=0 ;fclose(fp);/*保存订票人的信息*/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 cant be opened!“);return ;p=k-next ;while(p)if(fwrite(p,sizeof(bookMan),1,fp)=1)p=p-next ;count+;else flag=0 ;brea

19、k ;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(sizeof(bookMan);k-next=NULL ;h=k

20、;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(!fe

21、of(fp2)t=(bookMan*)malloc(sizeof(bookMan);if(fread(t,sizeof(bookMan),1,fp2)=1)t-next=NULL ;h-next=t ;h=t ;count2+;fclose(fp2);while(1)system(“cls“);printInterface();printf(“please choose the operation: “);scanf(“%d“,system(“cls“);if(sel=8)if(shoudsave=1)getchar();printf(“nthe file have been changed!

22、do you want to save it(y/n)?n“);scanf(“%c“,if(ch1=y|ch1=Y)SaveBookmanInfo(k);SaveTrainInfo(l);printf(“nThank you!You are welcome toon“);break ;switch(sel)case 1 :InsertTraininfo(l);break ;case 2 :QueryTrain(l);break ;case 3 :BookTicket(l,k);break ;case 4 :UpdateInfo(l);break ;case 5 :AdvicedTrains(l);break ;case 6 :SaveTrainInfo(l);SaveBookmanInfo(k);break ;case 7 :return 0;printf(“nplease press any key to continue.“);getch();return 0;

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报