火车票查询系统代码
c语言火车票管理系统基本代码

#include<conio.h>#include<stdio.h>#include<stdlib.h>#include<string.h>int shoudsave = 0;int count1 = 0, count2 = 0, mark = 0, mark1 = 0;struct train{char num[10];char city[10];char takeoffTime[10];char receiveTime[10];int price;int bookNum;};struct man{char num[10];char name[10];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 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 to file *");puts("* 7:quit the system *");puts("********************************************************"); }/*添加一个火车信息*/void InsertTraininfo(Link linkhead){struct node *p, *r, *s;char num[10];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;while (s){if (strcmp(s->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("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);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: %s\n", p->data.num);printf(">>city the train will reach: %s\n", p->data.city);printf(">>the time the train take off: %s\nthe time the train reach: %s\n", p->data.takeoffTime, p->data.receiveTime);printf(">>the price of the ticket: %d\n", p->data.price);printf(">>the number of booked tickets: %d\n", 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, findmess) == 0)return r;r = r->next;}}return 0;}void QueryTrain(Link l){Node *p;int sel;char str1[5], str2[10];if (!l->next){printf("There is not any record !");return;}printf("Choose 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;printf("\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){Node*r[10], *p;char ch, dem;bookMan*v, *h;int i = 0, t = 0;char str[10], str1[10], str2[10];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){r[i] = p;i++;}p = p->next;}printf("\n\nthe number of record have %d\n", i);for (t = 0; t<i; t++)printTrainInfo(r[t]);if (i == 0)printf("\n\t\t\tSorry!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(sizeof(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.bookNum = 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;}/*修改火车信息*/void UpdateInfo(Link l){Node*p;char findmess[20], 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("\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 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 people who have booked ticket:");scanf("%d", &p->data.bookNum);printf("\nmodifying record is sucessful!\n");shoudsave = 1;}elseprintf("\t\t\tcan't find the record!");}}elsemark1 = 0;}}void AdvicedTrains(Link l){Node*r;char str[10];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("\n\nplease select the fourth operation to book the ticket!\n");printTrainInfo(r);}r = r->next;}if (mar == 0)printf("\n\t\t\tyou can't book any ticket now!\n");}void SaveTrainInfo(Link l){FILE*fp;Node*p;int count = 0, flag = 1;fp = fopen("D:\\train.txt", "wb");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 %d\n", count);shoudsave = 0;}fclose(fp);}void SaveBookmanInfo(bookManLink k){FILE*fp;bookMan*p;int count = 0, flag = 1;fp = fopen("D:\\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;break;}}if (flag){printf("the number of the record which have been saved is %d\n", 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;fp1 = fopen("D:\\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("D:\\man.txt", "ab+");if ((fp2 == NULL)){printf("can't open 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){system("cls");printInterface();printf("please choose the operation: ");scanf("%d", &sel);system("cls");if (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'){SaveBookmanInfo(k);SaveTrainInfo(l);}}printf("\nThank you!!You are welcome too\n");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;}。
火车票查询系统

火车票查询系统摘要随着网络时代的快速发展,中国网民人数的持续增加,电子商务的普及以及中国现代物流的飞速发展,互联网法律法规的逐步完善,电子商务的环境已经初步形成,网上购物系统作为电子商务的一种主要实现形式必将得到进一步的普及和应用。
该系统主要为用户提供了会员注册、网上查询等功能;在设计方面,系统是典型的电子商务平台, 其开发基于B/S模式的网上销售的实现,采用的是ASP + ACCESS 模式。
该系统设计上采用三层结构、Web Service技术,使之在选用平台、采用技术上具有先进性、前瞻性、扩充性,从而保证建成的系统具有良好的稳定性、可扩充性。
从功能上来说,系统是比较完备的,系统以Web界面与用户交互,为用户提供信息并接受其操作,同时通过数据库管理系统来存储信息数据。
系统实现了对信息数据的浏览、查询、编辑和管理等基本数据库操作,采用了模块化设计方法,根据用户的需求及程序的应用与维护的易用性,将各个部分置于不同的模块当中,方便了程序的扩展与维护,同时建立了程序功能复用的基础。
本文所做火车票网上查询系统是一个根据现有的网上查询系统的现状而设计开发的电子商务平台,可以减少成本,提高工作效率。
关键词:网上查询;电子商务;ASP;交互AbstractWith the increasing number of netizens, the emergence of third--party payment means as well as the rapid development of modern logistic and the improvement of laws and regulations, the environment of e-commerce has formed in china. The shop online system which acted as one way to implement of electronic commerce will become more and more popular in the future.This system mainly to provide users with a registered member, preview tourist attractions, tickets online, provides the ticket for the administrator management, customer information management and information management, advertising spots link management etc. Function. In the design, system is a typical e-commerce sales platform, its development based on B/S model, online sales by ASP + ACCESS mode. Choose ACCESS database of backstage supporter's database. This system is used on three-layer structure design, Web Service technology, make in selecting, using the platform with advanced technology, prospectie, expand, and ensure the completion of the system has a good stability and extensibility. Using software component, system structure, development, business and separated, logic and data: In a unified service interface standard as the core, the use of open standards. From the function, system is relatively complete system with Web interface and the user interaction, and provide information and accept its operation, and through a database management system to store information and data. System of data to browse, query, editing and management database, the basic operating modular design methods, according to user's requirements and procedures of application and maintenance of facility, and the different parts will be placed among modules, convenient maintenance and expansion of the program, and established the basic program function reuse.The tourist attractions do online ticketing system is an online ticketing system according to the current situation of the development and design of e-commerce platform. It not only can expand the scale and influence the market business, and can reduce the operating costs, improve work efficiency.Key words:Online ticketing; e-commerce;ASP; interacti目录1绪论 (4)1.1课题现状 (4)1.2课题开发目的 (4)1.3课题关键技术 (5)1.3.1 ASP简介 (5)1.3.2 Dreamweaver (5)1.3.3 ACCESS (6)1.3.4 HTML(Hyper Text Markup Language) (6)2 可行性研究 (6)2.1资源可行性 (7)2.2技术可行性 (7)2.3经济可行性 (7)2.4社会的可行性 (7)3 系统需求分析 (8)3.1目标和任务 (8)3.2系统功能分析 (8)3.2.1 查询功能分析 (8)3.2.2 网站的界面设计 (8)3.3网站业务流程 (9)3.3.1 火车票网上查询系统的业务流程介绍 (9)3.3.2 系统的设计流程图 (9)4 系统概要设计 (10)4.1系统结构设计目标 (10)4.1.1 系统HIPO图 (10)4.1.2 系统功能模块介绍 (11)4.1.2.1登录模块 (11)4.1.2.2 注册模块 (11)4.1.2.3查询模块 (11)4.1.2.4用户管理模块 (11)4.2数据库结构设计 (11)4.2.1 数据库概念结构设计 (11)4.2.2数据库逻辑结构 (13)5 系统详细设计 (14)5.1系统总体结构图 (14)5.2过程设计 (15)5.2.1.系统用户权限的系统主处理流程 (16)5.2.2.车次信息查询处理流程 (17)6 系统运行与测试 (18)6.1系统调试 (18)6.2测试与运行 (18)6.2.1.系统管理员登陆首页 (18)6.2.2系统用户登陆注册首页 (19)6.2.3.车次查询界面 (19)6.2.4.车次查询结果 (20)结束语 (20)致谢 (21)参考文献 (21)附录 (21)1 绪论网上查询,相对于传统查询方式而言,是随着现代信息技术的发展而产生的一种新型查询方式,是一种消费者和工作人员分离的、非面对面的查询方式,是一种跨地区的查询模式。
火车票购票系统实验报告

火车票售票系统一、实验目的:1、熟练掌握数据库设计原理及模型构建软件PowerDesignerd 的使用。
2、熟练掌握Visual Studio 2008的使用。
3、实现方便、快捷使用火车票购票系统查票、购票、退票等功能。
4、实现系统的安全性设置,使系统具有一定的维护功能。
二、实验设备及软件:PC 机一台、Visual Studio 2008、SQL SERVER 2000三、需求分析: 3.1 功能分析:功能模块图教师评阅意见:签名: 年 月 日实验成绩:火车票售票系统新用户注册 购票 、预约余 票 查询 退 票 票价查询1、新用户注册模块:新用户注册需要新用户填入自己的基本信息包括用户名、密码和确认密码),详细的购票需要信息(包括姓名、性别、出生日期、证件类型、证件号码)以及联系方式(包括手机号码、电子邮箱、地址),只有当所有的信息格式填写正确和填写完全后才能注册成功。
2、购票/预订模块:购票/预订模块需要用户登录后,输入需要购票的出发站、目的站和出发日期后即可显示可购票,选择自己需要的票即可购票,点击购票则购票成功。
3、余票查询模块:余票查询模块需要用户在登录进入售票系统后点击余票查询按钮,按照要求填入出发地、目的地,选择出发日期,选择填入出发车次,完成输入后即可在界面下方看到所有满足要求的查询结果。
4、退票模块:退票模块需要用户在登录后,进入退票界面,即可显示登录用户所有订单,选择需要退票的订单,点击退票按钮即可退票。
5、票价查询模块:票价查询模块同样需要用户在登录进入售票系统后点击余票查询按钮,按照要求填入出发地、目的地,选择出发日期,选择填入出发车次,完成输入后即可在界面下方看到所有满足要求的查询结果。
3.2 流程图:火车票售票系统业务流程图如下图所示:1、新用户注册及登录流程图:新用户填写失败注册信息提交注册成功2、购票/预订流程图:填写失败成功2、余票查询流程图:填写显示3、退票流程图:登陆失 败 显示成功 出 发 站 目 的 站 出 发 日 期 用 户购 票 用 户 出 发 站 目 的 站 出 发 日 期 余 票 信 息用 户 退票界面所 有 订 单 退 票4、票价查询流程图:用户登陆票价查询显示车票票价四、数据库结构设计:4.1 E-R模型的建立:E-R模型由新用户注册、登录界面、购票、余票查询、票价查询这五个实体构成。
12306回参解析

12306回参解析
12306是中国铁路客户服务中心的官方网站,用于购买火车票和查询相关信息。
回参解析是指对12306网站返回的数据进行解析和处理的过程。
在12306网站上,用户进行车票查询、购票等操作后,系统会返回一段数据,通常是以JSON格式或HTML格式呈现。
回参解析的目的是提取有用的信息,如车次、出发时间、到达时间、座位信息等,并将其展示给用户或进行进一步的处理。
回参解析需要考虑以下几个方面:
1. 数据格式解析,根据返回的数据格式,如JSON或HTML,使用相应的解析方法进行数据提取。
对于JSON格式,可以使用JSON 解析库将数据转化为可操作的对象;对于HTML格式,可以使用HTML解析库进行解析。
2. 数据字段提取,根据业务需求,确定需要提取的字段,并编写相应的代码进行字段提取。
例如,需要提取车次信息,则可以通过遍历数据对象的方式提取出所有的车次信息。
3. 数据清洗和处理,有时候返回的数据可能存在噪声或不完整的情况,需要进行数据清洗和处理。
例如,对于时间字段,可能需要进行格式化或转换为特定的时间格式。
4. 错误处理,在回参解析过程中,可能会出现一些错误,如网络请求失败、数据格式异常等。
需要编写相应的错误处理代码,以确保程序的稳定性和可靠性。
总之,回参解析是对12306网站返回数据的处理过程,通过解析和提取有用的信息,为用户提供准确、完整的车票查询和购票服务。
火车票查询系统代码

if(strcmp(numorcity,"num")==0) 于判断 {
// ; while(r) { if(strcmp(r->data.getnum(),findmess)==0) return r ; r=r->next ; } } else if(strcmp(numorcity,"city")==0) { r=l->next ; while(r) { if(strcmp(r->data.getcity(),findmess)==0) return r ; r=r->next ; } } return 0 ; } void chaxuntrain(Link l) // 查询火车信息 { char t='y'; while(t=='y') { Node *p ; int sel ; //查询方式代号(1和2) char str1[5],str2[10]; if(!l->next) //指向链表的最后尾段, 即没有记录 {cout<<" 非常抱歉,这里没有相关记录 !"<<endl; return ; } cout<<" 选择查询方式:\n 1:根据车次查询;\n 2:根据到达的城市查询:"<<endl;
if(fp==NULL) { cout<<" 文件无法打开!" ; return ; } p=l->next ; while(p) { if(fwrite(p,sizeof(Node),1,fp)==1) //fwrite,写内 容(Node)到流中,c库函数, { p=p->next ; count++; } else { flag=0 ; break ; } } if(flag) { cout<<" 以上"<<count<<"个train的信息已经被保 存"<<endl; shoudsave=0 ; } fclose(fp); //文件关闭 } int main() { FILE*fp1 ; Node*p,*r ; Link l ; int sel ; l=(Node*)malloc(sizeof(Node));
12306火车票查询接口代码文档及返回示例

12306实时余票查询接口代码文档及返回示例在即将到来的双十二,在聚合数据平台上的12306实时余票查询接口将参与“暖冬不如低价活动”,主打汽车和金融两类数据接口。
此次我们将分享下12306实时余票查询接口代码文档及返回示例,可查询实时火车票余票,包括车次、车次始发站、车次终点站、出发时间、到达时间、车次类型、总历时时间等等。
接口名称:12306实时余票查询接口接口平台:聚合数据接口地址:/train/yp支持格式:JSON/XML请求方式:HTTP GET/POST请求示例:/train/yp?key=申请的KEY&dtype=json&from=%E4%B8%8A%E6%B5%B7%E8%99%B9%E6%A1%A5&to=%E6% B8%A9%E5%B7%9E&date=2014-06-28&tt=接口备注:火车余票查询12306实时余票查询接口调用代码JSON返回示例:{"reason": "查询成功","result": [{"train_no": "D2287", /*车次*/"start_station_name": "上海虹桥", /*车次始发站*/"end_station_name": "深圳北", /*车次终点站*/"from_station_name": "上海虹桥", /*出发站*/"to_station_name": "温州南", /*到达站*/"start_time": "06:25", /*出发时间*/"arrive_time": "10:53", /*到达时间*/"train_class_name": "动车", /*车次类型*/"day_difference": "0", /*历时天数*/"lishi": "04:28", /*总历时时间*/"gr_num": "--", /*高级软卧:-- 说明无该席位*/"qt_num": "--", /*其他*/"rw_num": "--", /*软卧*/"rz_num": "--", /*软座*/"tz_num": "--", /*特等座*/"wz_num": "无", /*无座*/"yw_num": "--", /*硬卧*/"yz_num": "--", /*硬座*/"ze_num": "无", /*二等座*/"zy_num": "无", /*一等座*/"swz_num": "--" /*商务座*/ },{"train_no": "D3203","start_station_name": "上海虹桥","end_station_name": "厦门北","from_station_name": "上海虹桥","to_station_name": "温州南","start_time": "06:30","arrive_time": "11:09","train_class_name": "动车","day_difference": "0","lishi": "04:39","gr_num": "--","qt_num": "--","rw_num": "--","rz_num": "--","tz_num": "--","wz_num": "无","yw_num": "--","yz_num": "--","ze_num": "无","zy_num": "无","swz_num": "--"},{"train_no": "G7501","start_station_name": "上海虹桥","end_station_name": "苍南","from_station_name": "上海虹桥","to_station_name": "温州南","start_time": "07:00","arrive_time": "11:00","train_class_name": "","day_difference": "0","lishi": "04:00","gr_num": "--","qt_num": "--","rw_num": "--","rz_num": "--","tz_num": "--","wz_num": "165","yw_num": "--","yz_num": "--","ze_num": "无","zy_num": "无","swz_num": "15"}],"error_code": 0}。
火车票售票系统源代码

public void actionPerformed(ActionEvent e){
JFileChooser openfile = new JFileChooser();
p2.add(jtf4);
p2.add(jlb6);
p2.add(jtf5);
p2.add(jlb7);
p2.add(jtf6);
p2.add(jbt1);
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);
inputfile = new FileInputStream(filename);
int len = 0;
// 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中
FileReader in = new FileReader(filename.getAbsoluteFile());
JLabel jlb5=new JLabel(" 身份证号");
JLabel jlb6=new JLabel(" 工作");
JLabel jlb7=new JLabel(" 电话");
final JTextField jtf1=new JTextField(10);
final JTextField jtf2=new JTextField(10);
JOptionPane.showMessageDialog(panel, error_message
);
火车票管理系统1

endif
系统进入退票管理也是通过两个方法来实现,用户可以直接进入退票环节,也可以从订单查询环节进入。订票相关信ele * from customer
if this.caption="订票"
this.caption="保存订票记录"
this.parent.tag=str(recno())
对于数据更新,需要得到如下信息:
被更新的关系。
每个关系上的更新操作条件所涉及的属性。
修改操作要改变的属性值。
需要注意的是,数据库上运行的事务会不断的变化、增加或减少,以后需要根据上述设计信息的变化调整数据库的物理结构。
5程序设计与调试及运行5.1火车票管理系统界面
图1火车票管理系统界面
代码如下:
登录系统:
NOTNULL
性别
Char(2)
电话
char(20)
表5订票表
字段名
数据类型
是否可空
说明
订单号
char(20)
NOT NULL
(主键)
订票方式
Char(20)
表6退票表
字段名
数据类型
是否可空
说明
订单号
char(20)
NOT NULL
(主键)
订票方式
Char(20)
表7查询表
字段名
数据类型
是否可空
说明
replace customer.座位号with thisform.Text2.TEXT
messagebox("订票成功!","dp")
else
messagebox("该车票不存在!","dp")
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
strcpy(chufatime,chufa); strcpy(daodatime,daoda); price=price2; booknum=booknum2; } }; typedef struct node 构 { train data ; struct node * next ; }Node,*Link ; void tianjiatrain(Link linkhead) //添加火车信息 { char num[10]; // 列车号 char city[10]; // 目的城市 char chufatime[10]; // 出发时间 char daodatime[10]; // 到达时间 double price; // 票价 int booknum ; struct node *p,*r,*s ;//定义指向火车信息链表的3个指针 r = linkhead ; s = linkhead->next ; while(r->next!=NULL) r=r->next ; while(1) { cout<<" 请输入列车号 (0 是返回)"; cin>>num; if(strcmp(num,"0")==0) //strcmp,串 比较函数,用于判断num是否为0 break ; while(s) // 判断是否已经存在 { if(strcmp(s->data.getnum(),num)==0)//strcmp,串 比较函数,用于判断data->num是否与num相同 { cout<<" 车次"<<num<<"已经存在"<<endl; return ; } // 定义火车信息链表的结点结
if(fp==NULL) { cout<<" 文件无法打开!" ; return ; } p=l->next ; while(p) { if(fwrite(p,sizeof(Node),1,fp)==1) //fwrite,写内 容(Node)到流中,c库函数, { p=p->next ; count++; } else { flag=0 ; break ; } } if(flag) { cout<<" 以上"<<count<<"个train的信息已经被保 存"<<endl; shoudsave=0 ; } fclose(fp); //文件关闭 } int main() { FILE*fp1 ; Node*p,*r ; Link l ; int sel ; l=(Node*)malloc(sizeof(Node));
s=s->next ; } p = (struct node*)malloc(sizeof(struct node)); //malloc,内存分配函数 cout<<" 请输入火车到达的城市:"; cin>>city; cout<<" 请输入火车出发的时间:"; cin>>chufatime; cout<<" 请输入火车到达的时间:"; cin>>daodatime; cout<<" 请输入火车票的价格:"; cin>>price; cout<<" 请输入您需要的票的数目:"; cin>>booknum; p>data.fuzhi(num,city,chufatime,daodatime,price,booknum); p->next=NULL ; r->next=p ; r=p ; shoudsave = 1 ; } } void showtrainxinxi(struct node*p) { cout<<" \n下面是您需要的火车的信息:" ; cout<<"\n 车次: "<<p->data.getnum()<<endl <<" 火车到达的城市: "<<p->data.getcity()<<endl <<" 火车出发的时间: "<<p->data.getchufatime()<<endl <<" 火车到达的时间: "<<p->data.getdaodatime()<<endl <<" 火车票的价格: "<<p->data.getprice()<<endl <<" 所提供的票数: "<<p->data.getbooknum() <<endl; } struct node * Locate1(Link numorcity[])//查询方式子函数 { Node*r ; l,char findmess[],char // 输出火车票信息
if(strcmp(numorcity,"num")==0) 于判断 {
//strcmp,串比较函数,用
r=l->next ; while(r) { if(strcmp(r->data.getnum(),findmess)==0) return r ; r=r->next ; } } else if(strcmp(numorcity,"city")==0) { r=l->next ; while(r) { if(strcmp(r->data.getcity(),findmess)==0) return r ; r=r->next ; } } return 0 ; } void chaxuntrain(Link l) // 查询火车信息 { char t='y'; while(t=='y') { Node *p ; int sel ; //查询方式代号(1和2) char str1[5],str2[10]; if(!l->next) //指向链表的最后尾段, 即没有记录 {cout<<" 非常抱歉,这里没有相关记录 !"<<endl; return ; } cout<<" 选择查询方式:\n 1:根据车次查询;\n 2:根据到达的城市查询:"<<endl;
cout<<" * 4: 退出 *" <<endl; cout<<" \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3"<<endl; cin>>sel; switch(sel) {case 1 : tianjiatrain(l);break ; case 2 : baocuntrain(l);break ; case :return 0; } } return 0; }
//malloc,内存分配函
数,c库函数 l->next=NULL ; r=l ; fp1=fopen("E:\\train.txt","ab+");//fopen,打开一个流,c 库函数 if((fp1==NULL)) { cout<<" 文件无法打开!" ; return 0 ; } while(!feof(fp1)) //检测流上(fp1)的文件结束符 ,c库函数 { p=(Node*)malloc(sizeof(Node)); if(fread(p,sizeof(Node),1,fp1)==1) //从一个流中 读数据 ,c库函数 { p->next=NULL ; r->next=p ; r=p ; } } fclose(fp1); while(1) {cout<<" ****************************************" <<endl; cout<<" * 欢迎使用火车票查询系统 *"<<endl; cout<<" \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3 \3\3"<<endl; cout<<" * 请选择操作 *" <<endl; cout<<" * 1: 插入火车信息 *" <<endl; cout<<" * 2: 保存火车信息 *" <<endl; cout<<" * 3: 查询火车信息 *" <<endl;
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream.h> int shoudsave=0 ,mark=0 ; class train { char num[10]; // 列车号 char city[10]; // 目的城市 char chufatime[10]; // 出发时间 char daodatime[10]; // 到达时间 double price; // 票价 int booknum ; // 票数 public: train() { } train(train &t) { strcpy(num,t.num); strcpy(city,t.city); strcpy(chufatime,t.chufatime); strcpy(daodatime,t.daodatime); price=t.price; booknum=t.booknum; } ~train(){} char *getnum(){return num;} char *getcity(){return city;} char *getchufatime(){return chufatime;} char *getdaodatime(){return daodatime;} double getprice(){return price;} int getbooknum (){return booknum;} void fuzhi(char *num2,char *city2,char *chufa, char *daoda,double price2,int booknum2) { strcpy(num,num2); strcpy(city,city2);