热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c语言程序设计火车站售票系统,C语言程序火车站售票系统程序

《C语言程序-火车站售票系统程序》由会员分享,可在线阅读,更多相关《C语言程序-火车站售票系统程序(11页珍藏版)》请在人人文库网上搜索。1、实用标准火

《C语言程序-火车站售票系统程序》由会员分享,可在线阅读,更多相关《C语言程序-火车站售票系统程序(11页珍藏版)》请在人人文库网上搜索。

1、实用标准火车站售票查询系统:#include #include #include #include int shoudsave=0 ;int count1=0,count2=0,mark=0,mark1=0 ;/*定义存储火车信息的结构体*/struct trainchar num10;/* 列车号 */char city10;/* 目的城市 */char takeoffTime10;/*发车时间 */char receiveTime10;/*到达时间 */int price;/* 票价*/int bookNum ;/* 票数 */;/*订票人的信息*/ struct manchar num1。

2、0;/*ID*/char name10;/* 姓名 */int bookNum ;/* 需求的票数*/;/*定义火车信息链表的结点结构*/ typedef struct nodestruct train data ;struct node * next ;Node,*Link ;/*定义订票人链表的结点结构*/typedef struct peoplestruct man data ;struct people*next ;bookMan,*bookManLink ;/*初始界面*/ void printInterface()文档puts(I*”);puts(“*Welcome to use 。

3、the system of booking tickets);puts(I*”);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 to fil。

4、e*);puts(*7:quit the system*);puts(*);/*添加一个火车信息*/void In sertTra inin fo(L ink lin khead)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 ;/*判断是否已经存在*/w。

5、hile(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(lnput the city where the train will reach:);scanf(%s,p-data.city);printf(Input the time which the train take off:);scanf(%s,p-dat。

6、a.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(lnput the number of booked tickets:);scanf(%d,&p-data.bookNum);p-next=NULL ;r-next=p ;r=p ;shoudsave = 1 ;/*打印火车票信息*/void pri ntTra inIn fo(。

7、struct n ode*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 trainreach: %sn,p-data.takeoffTime,p-data.receiveTime);printf(the price of the ticket:%dn,p-data.。

8、price);printf(the number ofbooked 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)=O)r=l-next ;while(r)if(strcmp(r-data.city,。

9、findmess)=O)return r;r=r-next ;return 0 ;/*查询火车信息*/void QueryTrain(Link I)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,&sel);if(sel=1)printf(Input the the numbe。

10、r of train:);scanf(%s,str1);p=Locate1(l,str1,num);if(p)pr in tTra inIn fo(p);elsemark1=1 ;pri ntf(nthe file cant be foun d!);else if(sel=2)prin tf(I nput the city:);sca nf(%s,str2);p=Locate1(l,str2,city);if(p)pr in tTra inIn fo(p);elsemark1=1 ;pri ntf(nthe file cant be foun d!“);/*订票子模块*/void BookTi。

11、cket(Li nk l,bookMa nLink 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.city,str)=0)ri=p ;i+;p=p-n ext ;printf(nnthe number of record ha。

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

13、xt=h ;v=h ;printf(nLucky!you have booked a ticket!); getch();shoudsave=1 ;bookMa n*Locate2(bookMa nLink k,char fin dmess)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(n。

14、there isnt record for you to modify!n); return ;elseQueryTrain(l);if(mark1=0)printf(nDo 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);print。

15、f(Input new city the train will reach:);scanf(%s, &p-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,&p-data.price);printf(Input new number of pe。

16、ople who have booked ticket:);scanf(%d,&p-data.bookNum);printf(nmodifying record is sucessful!n);shoudsave=1 ;else printf(tttcant find the record!);elsemark1=0 ;void AdvicedTrains(Link l)Node*r ;char str1O;int mar=0 ;r=l-next ;printf(Iuput the city you want to go:);scanf(%s,str);while(r)if(strcmp(r-。

17、data.city,str)=0&r-data.bookNumnext ;if(mar=0)printf(ntttyou cant book any ticket now!n);/*保存火车信息*/void SaveTrainlnfo(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 ;。

18、count+;elseflag=0 ;break ;if(flag)prin tf(the nu mber of the record which have bee n saved is %dn ,co unt); shoudsave=0 ;fclose(fp);/*保存订票人的信息*/void SaveBookmanlnfo(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-ne。

19、xt ;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 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 sei ;l=(Node*)malloc(siz。

20、eof(Node);l-next=NULL ;r=l ;k=(bookMan*)malloc(sizeof(bookMan);k-next=NULL ;h=k ;fp仁 fopen(c:train.txt,ab+);if(fp1=NULL)prin tf(ca nt ope n 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=fope n(c:。

21、ma n. txt,ab+);if(fp2=NULL)prin tf(ca nt ope n the file!);return 0 ;while(!feof(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)clrscr();printlnterface();printf(please choose the operation:);scanf(%d,&sel);clrscr();i。

22、f(sel=8)if(shoudsave=1)getchar();printf(nthe file have been changed!do you want to save it(y/n)?n);scanf(%c,& ch1);if(ch1=y|ch1=Y)SaveBookmanlnfo(k);SaveTrainlnfo(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 :Updatelnfo(l);break ;case 5 :AdvicedTrains(l);break ;case 6 :SaveTrainlnfo(l);SaveBookmanlnfo(k);break ;case 7 :return 0;printf(nplease press any key to continue);getch();return 0。



推荐阅读
  • 本文介绍了使用哈夫曼树实现文件压缩和解压的方法。首先对数据结构课程设计中的代码进行了分析,包括使用时间调用、常量定义和统计文件中各个字符时相关的结构体。然后讨论了哈夫曼树的实现原理和算法。最后介绍了文件压缩和解压的具体步骤,包括字符统计、构建哈夫曼树、生成编码表、编码和解码过程。通过实例演示了文件压缩和解压的效果。本文的内容对于理解哈夫曼树的实现原理和应用具有一定的参考价值。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • eclipse学习(第三章:ssh中的Hibernate)——11.Hibernate的缓存(2级缓存,get和load)
    本文介绍了eclipse学习中的第三章内容,主要讲解了ssh中的Hibernate的缓存,包括2级缓存和get方法、load方法的区别。文章还涉及了项目实践和相关知识点的讲解。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文介绍了游标的使用方法,并以一个水果供应商数据库为例进行了说明。首先创建了一个名为fruits的表,包含了水果的id、供应商id、名称和价格等字段。然后使用游标查询了水果的名称和价格,并将结果输出。最后对游标进行了关闭操作。通过本文可以了解到游标在数据库操作中的应用。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • Java编程实现邻接矩阵表示稠密图的方法及实现类介绍
    本文介绍了Java编程如何实现邻接矩阵表示稠密图的方法,通过一个名为AMWGraph.java的类来构造邻接矩阵表示的图,并提供了插入结点、插入边、获取邻接结点等功能。通过使用二维数组来表示结点之间的关系,并通过元素的值来表示权值的大小,实现了稠密图的表示和操作。对于对稠密图的表示和操作感兴趣的读者可以参考本文。 ... [详细]
  • 本文介绍了GTK+中的GObject对象系统,该系统是基于GLib和C语言完成的面向对象的框架,提供了灵活、可扩展且易于映射到其他语言的特性。其中最重要的是GType,它是GLib运行时类型认证和管理系统的基础,通过注册和管理基本数据类型、用户定义对象和界面类型来实现对象的继承。文章详细解释了GObject系统中对象的三个部分:唯一的ID标识、类结构和实例结构。 ... [详细]
author-avatar
手机用户2502923017
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有