C语言课程设计火车票系统源代码.doc

C语言课程设计火车票系统源代码.doc

ID:53118141

大小:21.19 KB

页数:12页

时间:2020-04-01

C语言课程设计火车票系统源代码.doc_第1页
C语言课程设计火车票系统源代码.doc_第2页
C语言课程设计火车票系统源代码.doc_第3页
C语言课程设计火车票系统源代码.doc_第4页
C语言课程设计火车票系统源代码.doc_第5页
资源描述:

《C语言课程设计火车票系统源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、.#include#include#include//火车票结构体类型//typedefstructNode{intnum;//编号//charname[20];//起点和终点//chartime[5];//出发时间//intprice;//车票价格//intamount;//剩余数量//structNode*next;}Node;//创建链表并输入数据//structNode*creat(){structNode*head,*r,*s;inti=0

2、;charchoice;head=(structNode*)malloc(sizeof(structNode));head->next=NULL;r=head;do{s=(structNode*)malloc(sizeof(structNode));s->next=NULL;printf("请输入第%d种火车票的信息:",++i);printf("请输入火车的编号:");scanf("%d",&s->num);printf("起点和终点:");scanf("%s",s->name);printf("出发

3、时间:");scanf("%s",s->time);printf("车票价格:");scanf("%d",&s->price);printf("剩余数量:");scanf("%d",&s->amount);r->next=s;r=s;printf("Continue?(Y/N)");scanf("%s",&choice);}while(choice=='Y'

4、

5、choice=='y');r->next=NULL;return(head);}..//将单链表中的信息保存到文件1.txt中//voidsave(

6、structNode*h){structNode*s;FILE*fp;charfilename[10]="1.txt";fp=fopen("1.txt","wt");if(fp==NULL){printf("写文件出错,按任意键退出!");getchar();exit(1);}for(s=h->next;s!=NULL;s=s->next)fprintf(fp,"%d%s%s%d%d",s->num,s->name,s->time,s->price,s->amount);getchar();fclo

7、se(fp);}//从文件1.txt中读取信息并存入单链表中//structNode*read(){structNode*head,*r,*s;FILE*fp;charfilename[10]="zl.txt";fp=fopen("1.txt","rt");if(fp==NULL){printf("读文件错误,按任意键退出!");getchar();exit(1);}head=(structNode*)malloc(sizeof(structNode));head->next=NULL;r=head;whi

8、le(!feof(fp)){s=(structNode*)malloc(sizeof(structNode));fscanf(fp,"%d%s%s%d%d",&s->num,s->name,s->time,&s->price,&s->amount);r->next=s;r=s;}r->next=NULL;fclose(fp);returnhead;..}//将链表中的数据输出//voidprint(structNode*h){structNode*s;printf("火车票信息如下:");print

9、f("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");printf("编号起点和终点出发时间车票价格剩余票数:");for(s=h->next;s->next!=NULL;s=s->next){printf("%d%10s%5s%10d%6d",s->num,s->name,s->time,s->price,s->amount);}}//链表查询//structNode*find(structNode*h){inti,j;chars[20];p

10、rintf("tt查询方法有以下几种:");printf("tt1.火车票编号");printf("tt2.起点和终点");printf("tt3.出发时间");printf("tt4.车票价格");printf("tt5.剩余票数");printf("请输入您要查询的方法的序号:");scanf("%d",&i);switch(i){case1:printf("请

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。