C语言火车票管理系统 (1)
c语言课程设计车票管理系统

c语言课程设计车票管理系统车票管理系统是一种用于管理车票信息的软件系统,它可以方便地记录和查询车票的相关信息,包括车票的购买、使用和退款等操作。
本文将详细介绍车票管理系统的设计与实现。
一、系统需求分析车票管理系统的主要功能包括:车票信息的录入与管理、车票的购买与退款、车票的查询与打印等。
具体需求如下:1. 车票信息的录入与管理:系统管理员可以录入车票的基本信息,包括车次、出发地、目的地、出发时间、到达时间、票价等。
2. 车票的购买与退款:乘客可以通过系统购买车票,并可以根据需要进行退款操作。
购买车票时需要提供乘客的相关信息,包括姓名、身份证号、联系电话等。
3. 车票的查询与打印:乘客可以通过系统查询车票的相关信息,并可以选择打印车票。
二、系统设计与实现1. 数据库设计:为了存储车票的相关信息,需要设计一个车票信息表,包括车次、出发地、目的地、出发时间、到达时间、票价等字段。
同时,还需要设计一个乘客信息表,包括姓名、身份证号、联系电话等字段。
2. 界面设计:车票管理系统的界面应该简洁明了,方便用户操作。
可以采用图形界面的形式,通过按钮、输入框等控件与用户进行交互。
3. 功能实现:a. 车票信息的录入与管理:系统管理员可以通过系统界面进行车票信息的录入与管理,包括新增车票、修改车票、删除车票等操作。
b. 车票的购买与退款:乘客可以通过系统界面选择购买车票或退款,购买车票时需要填写相关信息,并将购买信息保存到数据库中,退款时需要输入订单号进行操作。
c. 车票的查询与打印:乘客可以通过系统界面进行车票的查询,可以根据车次、出发地、目的地、出发时间等条件进行筛选,并可以选择打印车票。
三、系统运行流程1. 系统管理员登录系统,进入车票管理界面。
2. 管理员可以进行车票信息的录入与管理,包括新增、修改和删除车票。
3. 乘客通过系统界面选择购买车票,填写相关信息,系统将购买信息保存到数据库中,并生成订单号。
4. 乘客可以通过系统界面进行车票的查询,可以根据条件筛选需要的车票。
C语言 车票管理系统源程序

#include〈stdio。
h〉#include〈time.h> /*时间库函数*/#include<stdlib。
h> /*调用系统函数*/#include〈string。
h> /*串操作及内存操作函数*/ #include〈conio.h〉#include〈math。
h〉#define N 80 /*宏定义多条记录*/void maipiao(int s,int t);/*函数定义*/float times(int k);int hour(int k){switch(k){case 1:return 07;break;case 2:return 10;break;case 3:return 13;break;case 4:return 16;break;case 5:return 19;break;case 6:return 21;break;/*d到闽清一天的发车时间小时段*/ case 7:return 07;break;case 8:return 11;break;case 9:return 15;break;case 10:return 19;break;case 11:return 23;break; /*d到长乐一天的发车时间小时段*/ case 12:return 07;break;case 13:return 11;break;case 14:return 15;break;case 15:return 19;break;case 16:return 23;break;/*d到连江一天的发车时间小时段*/ case 17:return 07;break;case 18:return 11;break;case 19:return 16;break;case 20:return 20;break;/*d到永泰一天的发车时间小时段*/ case 21:return 07;break;case 22:return 12;break;case 23:return 17;break;case 24:return 22;break; /*d到福清一天的发车时间小时段*/ case 25:return 07;break;case 26:return 14;break;case 27:return 19;break;case 28:return 22;break;/*d到罗源一天的发车时间小时段*/ }}/*开车时间段*/ int minute(int k){switch(k){case 1:return 00;break;case 2:return 00;break;case 3:return 00;break;case 4:return 00;break;case 5:return 00;break;case 6:return 00;break;/*d到闽清一天的发车时间分钟段*/ case 7:return 00;break;case 8:return 00;break;case 9:return 00;break;case 10:return 00;break;case 11:return 00;break;/*d到长乐一天的发车时间分钟段*/ case 12:return 00;break;case 13:return 00;break;case 14:return 00;break;case 15:return 00;break;case 16:return 00;break;/*d到连江一天的发车时间分钟段*/ case 17:return 00;break;case 18:return 30;break;case 19:return 00;break;case 20:return 30;break;/*d到永泰一天的发车时间分钟段*/ case 21:return 00;break;case 22:return 30;break;case 23:return 00;break;case 24:return 30;break;/*d到福清一天的发车时间分钟段*/ case 25:return 30;break;case 26:return 00;break;case 27:return 30;break;case 28:return 30;break;/*d到罗源一天的发车时间分钟段*/ }}/*开车时间段*/ void wap(int k){switch(k){case 1:printf("闽清”);break;case 2:printf(”长乐");break;case 3:printf(”连江”);break;case 4:printf(”永泰”);break;case 5:printf(”福清”);break;case 6:printf("罗源");break;}}/*输入终点站的函数*/int shijian(){struct tm *ptr;time_t lt;lt =time(NULL);ptr=gmtime(<);printf(ctime(<));return 0;}/*输出当前时间的函数*/float times(int k){float t;if(k==1)t=1.5;if(k==2)t=3.0;if(k==3||k==4)t=4.0;if(k==5||k==6)t=4.5;return t;}/*输入行车时间的函数*/ int number(int k){int f;if(k==1||k==2)f=30;if(k==3||k==4)f=40;if(k==5||k==6)f=45;return f;}/*输入最大载客量的函数*/ int nownumber(int k,int i){int n=0;char filename[10];switch(i){case 1:strcpy(filename,”qiu1.txt”);break;case 2:strcpy(filename,”qiu2。
C语言编程---火车订票系统源代码

火车订票系统源码(一)#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>intshoudsave=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;/*票价*/intbookNum ;/*票数*/};/*订票人的信息*/struct man{charnum[10];/*ID*/char name[10];/*姓名*/intbookNum ;/*需求的票数*/};/*定义火车信息链表的结点结构*/typedefstruct node{struct train data ;struct node * next ;}Node,*Link ;/*定义订票人链表的结点结构*/typedefstruct people{struct man data ;struct people*next ;}bookMan,*bookManLink ;/* 初始界面*/voidprintInterface(){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("********************************************************"); }/*添加一个火车信息*/voidInsertTraininfo(Link linkhead){struct node *p,*r,*s ;charnum[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 ;}}/*打印火车票信息*/voidprintTrainInfo(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,charfindmess[],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 ;}/*查询火车信息*/voidQueryTrain(Link l){Node *p ;intsel ;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!");}}}/*订票子模块*/voidBookTicket(Link l,bookManLink k){Node*r[10],*p ;charch,dem ;bookMan*v,*h ;int i=0,t=0 ;charstr[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(bookManLinkk,charfindmess[]) {bookMan*r ;r=k->next ;while(r){if(strcmp(r->data.num,findmess)==0){mark=1 ;return r ;}r=r->next ;}return 0 ;}/*修改火车信息*/voidUpdateInfo(Link l){Node*p ;charfindmess[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 ;}}/*系统给用户的提示信息*/voidAdvicedTrains(Link l){Node*r ;charstr[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");}/*保存火车信息*/voidSaveTrainInfo(Link l){FILE*fp ;Node*p ;int count=0,flag=1 ;fp=fopen("c:\\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);}/*保存订票人的信息*/voidSaveBookmanInfo(bookManLink k){FILE*fp ;bookMan*p ;int count=0,flag=1 ;fp=fopen("c:\\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 ;intsel ;l=(Node*)malloc(sizeof(Node));l->next=NULL ;r=l ;k=(bookMan*)malloc(sizeof(bookMan));k->next=NULL ;h=k ;fp1=fopen("c:\\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("c:\\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;}11/11。
c语言课程设计车票管理系统

c语言课程设计车票管理系统车票管理系统是一个用于管理车票信息的软件系统。
它可以记录并管理车票的购买、退票、查询等操作,实现对车票信息的全面管理和统计。
本文将从需求分析、系统设计和实现三个方面来介绍车票管理系统的开发过程。
一、需求分析车票管理系统主要面向客户和管理员两类用户。
客户可以通过系统购买车票、查询车票信息,管理员可以管理车票信息、处理退票等操作。
1. 用户管理车票管理系统需要实现用户的注册和登录功能,以保证用户购票时的身份认证和信息安全。
2. 车次管理系统需要记录车次的信息,包括车次编号、起始站点、终点站点、发车时间、到达时间、票价等。
管理员可以对车次信息进行增删改查操作。
3. 车票管理系统需要记录车票的信息,包括车票编号、车次编号、座位号、购票人、购票时间等。
客户可以通过系统购买车票,管理员可以对车票信息进行增删改查操作。
4. 车票查询客户可以根据起始站点、终点站点和发车时间等条件来查询车票信息,以便选择合适的车次和座位。
5. 车票购买客户可以选择合适的车次和座位进行购票,系统需要实时更新车票信息,避免重复售票或超售情况的发生。
6. 车票退票客户可以通过系统进行退票操作,系统需要实时更新车票信息,并进行相应的退款处理。
二、系统设计基于需求分析的结果,我们可以设计出如下的系统架构:1. 用户管理模块包括用户注册、登录、信息修改等功能。
2. 车次管理模块包括车次信息的增删改查功能。
3. 车票管理模块包括车票信息的增删改查功能。
4. 车票查询模块根据用户输入的条件查询车票信息并展示给用户。
5. 车票购买模块根据用户选择的车次和座位进行购票,并更新车票信息。
6. 车票退票模块根据用户选择的车票进行退票,并更新车票信息和退款处理。
三、系统实现车票管理系统的实现主要依赖于数据库和编程语言。
我们可以选择使用MySQL作为数据库,使用C语言进行系统的开发。
1. 数据库设计根据需求分析的结果,我们可以设计出如下的数据库表结构:- 用户表:包括用户ID、用户名、密码等字段。
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];/*ID*/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("c:\\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("c:\\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("c:\\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("c:\\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++;}}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.......");} return 0; }。
C语言编写车票管理系统(2024)

引言概述:车票管理系统是一种用于管理车票信息,包括购票、退票、查询票务等功能的软件系统。
本文将以C语言为编程语言,详细阐述如何编写一个车票管理系统。
该系统可以方便管理者对车票信息进行操作,同时也提供给用户便捷的购票和查询功能。
正文内容:一、数据库设计1.1数据库表的建立1.2表中字段的设置1.3数据库的连接与操作1.4数据库的备份与恢复1.5数据库的维护与优化二、用户管理2.1用户注册2.2用户登录2.3用户信息修改2.4用户权限管理2.5用户数据备份与恢复三、车票管理3.1车票添加3.2车票查询3.3车票修改3.4车票删除3.5车票排序和筛选四、订单管理4.1订单4.2订单查询4.3订单修改4.4订单删除4.5订单统计和报表五、支付管理5.1支付方式的选择5.2支付状态的更新5.3支付记录的查询5.4退款管理5.5支付安全性保证总结:通过本文详细的阐述,我们了解到了如何使用C语言编写一个车票管理系统。
在系统的开发过程中,数据库设计、用户管理、车票管理、订单管理和支付管理等方面都需要详细考虑。
通过对每个模块的分析和设计,能够使系统更加高效、安全和易用。
在实际开发中,我们还需要根据具体需求进行对系统的优化和完善,保证系统能够满足用户的需求,并且能够稳定运行。
希望本文对您有所帮助,能够指导您在C语言中编写车票管理系统的开发过程。
引言概述:C语言编写车票管理系统是一个涉及到计算机编程技术的项目,旨在帮助车票销售员和管理员更好地管理和控制车票的销售与出票过程。
本文将详细介绍该系统的设计和实现过程,包括系统的功能需求、系统的结构设计、关键代码的实现以及系统的优化与改进。
正文内容:1.功能需求车票管理系统的功能需求包括但不限于:车票销售、车票查询、座位管理、车票退换等。
具体的系统功能要求涉及到对车票信息的录入、查询、修改和删除,车票的座位分配和座位的查询,以及对车票销售记录的统计和报表等功能。
1.1车票销售功能实现车票销售功能是车票管理系统的核心功能之一。
火车票售票系统(C语言顺序存储实现)

⽕车票售票系统(C语⾔顺序存储实现)储备知识:这个程序属于C语⾔基础训练题⽬,所以⽆需太多的复杂的语法和知识;本程序包含知识有:结构体,数组,简单的条件分⽀语句;(⽂章最后有全部代码)附上⼀张程序结构图:接下来就来看看怎么实现的吧1、定义结构体,记录车次信息;typedef struct train_infor{char number[10];//车次char start[20];//始发地char end[20];//终点站int year1,month1,day1,h1,m1;//发车⽇期时间int year2,month2,day2,h2,m2;//到达⽇期时间}train;2、定义⼀些程序中要⽤到的全局变量:int cnum=0;//记录总共有多少个列车信息;train info[10000];//结构体类型的数组⽤来保存所有的车次信息;train users[100][100];//⼆维数组⽤来保存⽤户信息,每⼀⾏可以⽤来表⽰⼀个⽤户的购票信息int vcs[100]={0};//⽤来记录每⼀个⼈⾃⼰账户的票数,初始全为0;3、管理员界⾯函数(这个函数⾥⾯会⽤到⼀些在后⾯才定义到的函数哦!看到不懂得函数可以往后翻翻看):admin_menu();int choose2;while(~scanf("%d",&choose2))//选择对应的操作;{switch(choose2){case1:create();break;case2:print();break;case3:query();break;case4:update();break;case5:insert();break;case6:dele();break;case0:return;//输⼊0直接退出整个函数default:printf("请选择有效操作对应编号哦!\n");break;}admin_menu();//每次操作结束后再次打印菜单栏}}4、按上述程序开始建造⽋缺的函数;管理员菜单:void admin_menu(){printf("***************************************************************\n"); printf("* 欢迎进⼊⽕车票信息管理系统 *\n"); printf("***************************************************************\n"); printf("* 1、录⼊⽕车票信息 *\n"); printf("* 2、显⽰⽕车票信息 *\n"); printf("* 3、查询⽕车票信息 *\n"); printf("* 4、修改⽕车票信息 *\n"); printf("* 5、添加⽕车票信息 *\n"); printf("* 6、删除⽕车票信息 *\n"); printf("* 0、退出 *\n");printf("***************************************************************\n"); }5、录⼊⽕车票信息:int sum,i;printf("请输⼊要录⼊的列车信息条数:");scanf("%d",&sum);printf("请依次输⼊车次始发地终点站发车时间(年/⽉/⽇时:分)到达时间(年/⽉/⽇时:分);\n");for(i=cnum;i<cnum+sum;i++)//录⼊信息从cnum开始的原因是避免管理员先进⾏插⼊或添加操作后再来录⼊数据,发⽣覆盖;同时这样可以多次进⾏录⼊操作(在之前的信息下继续添加)scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&inf o[i].m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);printf("录⼊成功!\n");cnum+=sum;return;}6、显⽰⽕车票信息:void print(){if(cnum==0){printf("⽆列车信息!\n");return;}int i;printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<cnum;i++)printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info[i]. day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);return;}7、查询⽕车票信息:void query(){int i;printf("请输⼊查询车次:");char ch[10];//记录要查询的车次scanf("%s",ch);for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info [i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);return;//找到后直接结束⽆需再查找}}printf("⽆此列车信息!\n");//如果找到前⾯就结束则不会运⾏到此处;所以运⾏到此处只能是没有找到;return;}8、修改⽕车票信息:int i;printf("请输⼊要修改的车次:");char ch[10];//记录要修改的车次scanf("%s",ch);//和查询⼀样先找到该列车所在的位置,然后对其进⾏修改for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {printf("该列车原信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info [i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);printf("请输⼊新的数据:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&i nfo[i].m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);printf("修改成功!\n");return;//修改后直接结束⽆需再进⾏}}printf("⽆此列车信息!\n");//如果找到前⾯就结束则不会运⾏到此处;所以运⾏到此处只能是没有找到;return;}9、添加⽕车票信息:void insert(){int i=cnum;printf("请输⼊插⼊的信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&info[i] .m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);cnum++;//列车信息总条数加⼀printf("插⼊成功!\n");return;}10、删除⽕车票信息:int i,vis=-1;printf("请输⼊要删除的车次:");char ch[10];//记录要删除的车次scanf("%s",ch);//和查询⼀样先找到该列车所在的位置,然后对其进⾏删除for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {vis=i;//将要删除的车次的下标保存下来,为后边的删除操作服务;break;//找到后就可以结束循环}}if(vis==-1)//vis初始值设为-1因为下标不存在负值,如果经过查找后还没变说明没有找到该车次所以可以直接结束{printf("⽆此列车信息!\n");return;}else{for(i=vis;i<cnum-1;i++)//vis为要删除列车信息的下标,要想把它删除只⽤把后边的信息依次往前进⾏覆盖即可;此处i<cnum-1是为了避免最后越界;{info[i]=info[i+1];}printf("删除成功!\n");cnum--;//列车信息总条数减⼀;return;}}11、⽤户界⾯(这个函数⾥⾯也会⽤到⼀些在后⾯才定义到的函数!看到不懂得函数可以往后翻翻看):void user(){int no;printf("请输⼊你的⽤户编码:");scanf("%d",&no);//记录⽤户编码⽤来对应的保存其购票信息user_menu();int choose3;while(~scanf("%d",&choose3))//记录⽤户选择的操作;{switch(choose3){case1:look_up(no);break;case2:out_print(no);break;case3:refund(no);break;case0:return;//输⼊0直接退出整个函数default:printf("请选择有效操作对应编号哦!\n");break;}user_menu();}}12、⽤户菜单:void user_menu(){printf("***************************************************************\n"); printf("* 欢迎进⼊⽕车票售票系统 *\n"); printf("***************************************************************\n"); printf("* 1、⽕车票区间查询 *\n"); printf("* 2、打印购票信息 *\n"); printf("* 3、退票 *\n"); printf("* 0、退出 *\n"); printf("***************************************************************\n"); }13、⽕车票区间查询:if(cnum==0){printf("⽆车次信息,请管理员进⾏车次信息录⼊!\n");return;}char starts[20];char ends[20];int cnums=0,i;//记录查询到的车次条数printf("请输⼊查询的起始终⽌区间(空格隔开哦!):\n");scanf("%s %s",starts,ends);for(i=0;i<cnum;i++){if(strcmp(starts,info[i].start)==0&&strcmp(ends,info[i].end)==0){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,i nfo[i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);cnums++;}}if(cnums==0){printf("⽆此区间车次信息!\n");return;}else{printf("------------------------\n");printf("| 是否购票 |\n");printf("------------------------\n");printf("| 1、是 | 2、否 |\n");printf("------------------------\n");int choose4;//记录⽤户的选择while(~scanf("%d",&choose4)){switch(choose4){case1:buy(no);break;case2:return;default:printf("请选择有效操作对应编号哦!\n");break;}printf("------------------------\n");printf("| 是否购票 |\n");printf("------------------------\n");printf("| 1、是 | 2、否 |\n");printf("------------------------\n");}}}14、买票:int i;printf("请输⼊你要购票的车次:\n"); char che[10];scanf("%s",che);for(i=0;i<cnum;i++){if(strcmp(che,info[i].number)==0){users[no][vcs[no]]=info[i];vcs[no]++;//该⽤户的购票数加⼀;printf("购票成功!\n");return;}}printf("⽆此列车信息!\n");return;}15、退票:int vis=-1,i;if(vcs[no]==0){printf("你还尚未购票哦!\n");return;}else{printf("你的购票信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<vcs[no];i++){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",users[no][i].number,users[no][i].start,users[no][i].end,users[no][i].y ear1,users[no][i].month1,users[no][i].day1,users[no][i].h1,users[no][i].m1,users[no][i].year2,users[no][i].month2,users[no][i].day2,users[no][i].h2,users[no][i]. m2);}printf("请输⼊退票车次:");char cs[10];scanf("%s",cs);for(i=0;i<vcs[no];i++){if(strcmp(cs,users[no][i].number)==0)//⽐较你所购票的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0{vis=i;//将要退票的车次的下标保存下来,为后边的删除操作服务;break;//找到后就可以结束循环}}if(vis==-1)//vis初始值设为-1因为下标不存在负值,如果经过查找后还没变说明没有找到该车次所以可以直接结束{printf("你尚未购买此列车车票!\n");return;}else{for(i=vis;i<vcs[no]-1;i++)//vis为要删除列车信息的下标,要想把它删除只⽤把后边的信息依次往前进⾏覆盖即可;此处i<vcs[no]-1是为了避免最后越界;{users[no][i]=users[no][i+1];}printf("退票成功!\n");vcs[no]--;//购票总条数减⼀;return;}}}16、打印购票信息:int i;if(vcs[no]==0){printf("⽆购票记录!\n");return;}else{printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<vcs[no];i++){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",users[no][i].number,users[no][i].start,users[no][i].end,users[no][i].y ear1,users[no][i].month1,users[no][i].day1,users[no][i].h1,users[no][i].m1,users[no][i].year2,users[no][i].month2,users[no][i].day2,users[no][i].h2,users[no][i]. m2);}}}17、主函数部分:int main(){printf("提⽰:整个输⼊过程请严格按照格式,标点均为英⽂!\n");printf("-------------请选择⾝份-------------\n");printf("| 1、管理员 | 2、⽤户 |\n");printf("| 0、结束程序 |\n");printf("------------------------------------\n");//输⼊1表⽰进⼊管理员界⾯,2进⼊⽤户界⾯int choose1;while(~scanf("%d",&choose1))//记录选择的序号,多组测试{if(choose1==0)break;switch(choose1){case1:admin();break;case2:user();break;default:printf("请选择有效操作对应编号哦!\n");break;}printf("-------------请选择⾝份-------------\n");printf("| 1、管理员 | 2、⽤户 |\n");printf("| 0、结束程序 |\n");printf("------------------------------------\n");}return0;}18、到此这个程序就可以运⾏了,以上就是各个部分的代码,希望你的程序也可以运⾏了( ̄︶ ̄)在此附上全部代码:#include<stdio.h>#include<stdlib.h>#include<string.h>//定义结构体,记录车次信息typedef struct train_infor{char number[10];//车次char start[20];//始发地char start[20];//始发地char end[20];//终点站int year1,month1,day1,h1,m1;//发车⽇期时间int year2,month2,day2,h2,m2;//到达⽇期时间}train;int cnum=0;//记录总共有多少个列车信息;train info[10000];//结构体类型的数组⽤来保存所有的车次信息;train users[100][100];//⼆维数组⽤来保存⽤户信息,每⼀⾏可以⽤来表⽰⼀个⽤户的购票信息int vcs[100]={0};//⽤来记录每⼀个⼈⾃⼰账户的票数,初始全为0;//录⼊⽕车票信息void create(){int sum,i;printf("请输⼊要录⼊的列车信息条数:");scanf("%d",&sum);printf("请依次输⼊车次始发地终点站发车时间(年/⽉/⽇时:分)到达时间(年/⽉/⽇时:分);\n");for(i=cnum;i<cnum+sum;i++)//录⼊信息从cnum开始的原因是避免管理员先进⾏插⼊或添加操作后再来录⼊数据,发⽣覆盖;同时这样可以多次进⾏录⼊操作(在之前的信息下继续添加)scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&inf o[i].m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);printf("录⼊成功!\n");cnum+=sum;return;}//显⽰⽕车票信息void print(){if(cnum==0){printf("⽆列车信息!\n");return;}int i;printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<cnum;i++)printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info[i]. day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);return;}//查询⽕车票信息void query(){int i;printf("请输⼊查询车次:");char ch[10];//记录要查询的车次scanf("%s",ch);for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info [i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);return;//找到后直接结束⽆需再查找}}printf("⽆此列车信息!\n");//如果找到前⾯就结束则不会运⾏到此处;所以运⾏到此处只能是没有找到;return;}//修改⽕车票信息void update(){int i;printf("请输⼊要修改的车次:");char ch[10];//记录要修改的车次scanf("%s",ch);//和查询⼀样先找到该列车所在的位置,然后对其进⾏修改for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {printf("该列车原信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,info [i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);printf("请输⼊新的数据:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&i nfo[i].m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);printf("修改成功!\n");return;//修改后直接结束⽆需再进⾏}}printf("⽆此列车信息!\n");//如果找到前⾯就结束则不会运⾏到此处;所以运⾏到此处只能是没有找到;return;}//添加⽕车票信息void insert(){int i=cnum;printf("请输⼊插⼊的信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");scanf("%s %s %s %d/%d/%d %d:%d %d/%d/%d %d:%d",info[i].number,info[i].start,info[i].end,&info[i].year1,&info[i].month1,&info[i].day1,&info[i].h1,&info[i] .m1,&info[i].year2,&info[i].month2,&info[i].day2,&info[i].h2,&info[i].m2);cnum++;//列车信息总条数加⼀printf("插⼊成功!\n");return;}//删除⽕车票信息void dele(){int i,vis=-1;printf("请输⼊要删除的车次:");char ch[10];//记录要删除的车次scanf("%s",ch);//和查询⼀样先找到该列车所在的位置,然后对其进⾏删除for(i=0;i<cnum;i++){if(strcmp(ch,info[i].number)==0)//⽐较所有的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0 {vis=i;//将要删除的车次的下标保存下来,为后边的删除操作服务;break;//找到后就可以结束循环}}if(vis==-1)//vis初始值设为-1因为下标不存在负值,如果经过查找后还没变说明没有找到该车次所以可以直接结束{printf("⽆此列车信息!\n");return;}else{for(i=vis;i<cnum-1;i++)//vis为要删除列车信息的下标,要想把它删除只⽤把后边的信息依次往前进⾏覆盖即可;此处i<cnum-1是为了避免最后越界;{info[i]=info[i+1];}printf("删除成功!\n");cnum--;//列车信息总条数减⼀;return;}}//管理员菜单void admin_menu(){printf("***************************************************************\n"); printf("* 欢迎进⼊⽕车票信息管理系统 *\n"); printf("***************************************************************\n"); printf("* 1、录⼊⽕车票信息 *\n"); printf("* 2、显⽰⽕车票信息 *\n"); printf("* 3、查询⽕车票信息 *\n"); printf("* 4、修改⽕车票信息 *\n"); printf("* 5、添加⽕车票信息 *\n"); printf("* 6、删除⽕车票信息 *\n"); printf("* 0、退出 *\n");printf("***************************************************************\n"); }//管理员界⾯void admin(){admin_menu();int choose2;while(~scanf("%d",&choose2))//选择对应的操作;{switch(choose2){case1:create();break;case2:print();break;case3:query();break;case4:update();break;case5:insert();break;case6:dele();break;case0:return;//输⼊0直接退出整个函数default:printf("请选择有效操作对应编号哦!\n");break;}admin_menu();//每次操作结束后再次打印菜单栏}}//买票void buy(int no){int i;printf("请输⼊你要购票的车次:\n");char che[10];scanf("%s",che);for(i=0;i<cnum;i++){if(strcmp(che,info[i].number)==0){users[no][vcs[no]]=info[i];vcs[no]++;//该⽤户的购票数加⼀;printf("购票成功!\n");return;}}printf("⽆此列车信息!\n");return;}//⽕车票区间查询void look_up(int no){if(cnum==0){printf("⽆车次信息,请管理员进⾏车次信息录⼊!\n");return;}char starts[20];char ends[20];int cnums=0,i;//记录查询到的车次条数printf("请输⼊查询的起始终⽌区间(空格隔开哦!):\n");scanf("%s %s",starts,ends);for(i=0;i<cnum;i++){if(strcmp(starts,info[i].start)==0&&strcmp(ends,info[i].end)==0){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",info[i].number,info[i].start,info[i].end,info[i].year1,info[i].month1,i nfo[i].day1,info[i].h1,info[i].m1,info[i].year2,info[i].month2,info[i].day2,info[i].h2,info[i].m2);cnums++;}}if(cnums==0){printf("⽆此区间车次信息!\n");return;}else{printf("------------------------\n");printf("| 是否购票 |\n");printf("------------------------\n");printf("| 1、是 | 2、否 |\n");printf("------------------------\n");int choose4;//记录⽤户的选择while(~scanf("%d",&choose4)){switch(choose4){case1:buy(no);break;case2:return;default:printf("请选择有效操作对应编号哦!\n");break;}printf("------------------------\n");printf("| 是否购票 |\n");printf("------------------------\n");printf("| 1、是 | 2、否 |\n");printf("------------------------\n");}}}//退票void refund(int no){int vis=-1,i;if(vcs[no]==0){printf("你还尚未购票哦!\n");return;}else{printf("你的购票信息:\n");printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<vcs[no];i++){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",users[no][i].number,users[no][i].start,users[no][i].end,users[no][i].y ear1,users[no][i].month1,users[no][i].day1,users[no][i].h1,users[no][i].m1,users[no][i].year2,users[no][i].month2,users[no][i].day2,users[no][i].h2,users[no][i]. m2);}printf("请输⼊退票车次:");char cs[10];scanf("%s",cs);for(i=0;i<vcs[no];i++){if(strcmp(cs,users[no][i].number)==0)//⽐较你所购票的列车信息⼀直到和输⼊的车次相同则找到并输出,字符串的⽐较要是⽤strcmp()函数;如果相等则为0{vis=i;//将要退票的车次的下标保存下来,为后边的删除操作服务;break;//找到后就可以结束循环}}if(vis==-1)//vis初始值设为-1因为下标不存在负值,如果经过查找后还没变说明没有找到该车次所以可以直接结束{printf("你尚未购买此列车车票!\n");return;}else{for(i=vis;i<vcs[no]-1;i++)//vis为要删除列车信息的下标,要想把它删除只⽤把后边的信息依次往前进⾏覆盖即可;此处i<vcs[no]-1是为了避免最后越界;{users[no][i]=users[no][i+1];}printf("退票成功!\n");vcs[no]--;//购票总条数减⼀;return;}}}//打印购票信息void out_print(int no){int i;if(vcs[no]==0){printf("⽆购票记录!\n");return;}else{printf("车次\t始发地\t终点站\t发车时间\t\t到达时间\n");for(i=0;i<vcs[no];i++){printf("%s\t%s\t%s\t%d/%02d/%02d %02d:%02d\t%d/%02d/%02d %02d:%02d\n",users[no][i].number,users[no][i].start,users[no][i].end,users[no][i].y ear1,users[no][i].month1,users[no][i].day1,users[no][i].h1,users[no][i].m1,users[no][i].year2,users[no][i].month2,users[no][i].day2,users[no][i].h2,users[no][i]. m2);}}}//⽤户菜单void user_menu(){printf("***************************************************************\n");printf("* 欢迎进⼊⽕车票售票系统 *\n");printf("***************************************************************\n");printf("* 1、⽕车票区间查询 *\n");printf("* 2、打印购票信息 *\n");printf("* 3、退票 *\n");printf("* 0、退出 *\n");printf("***************************************************************\n");}//⽤户界⾯void user(){int no;printf("请输⼊你的⽤户编码:");scanf("%d",&no);//记录⽤户编码⽤来对应的保存其购票信息user_menu();int choose3;while(~scanf("%d",&choose3))//记录⽤户选择的操作;{switch(choose3){case1:look_up(no);break;case2:out_print(no);break;case3:refund(no);break;case0:return;//输⼊0直接退出整个函数default:printf("请选择有效操作对应编号哦!\n");break;}user_menu();}}int main(){printf("提⽰:整个输⼊过程请严格按照格式,标点均为英⽂!\n");printf("-------------请选择⾝份-------------\n");printf("| 1、管理员 | 2、⽤户 |\n");printf("| 0、结束程序 |\n");printf("------------------------------------\n");//输⼊1表⽰进⼊管理员界⾯,2进⼊⽤户界⾯int choose1;while(~scanf("%d",&choose1))//记录选择的序号,多组测试{if(choose1==0)if(choose1==0)break;switch(choose1){case1:admin();break;case2:user();break;default:printf("请选择有效操作对应编号哦!\n");break;}printf("-------------请选择⾝份-------------\n");printf("| 1、管理员 | 2、⽤户 |\n");printf("| 0、结束程序 |\n");printf("------------------------------------\n");}return0;}。
C语言编程---火车订票系统源代码

#include <>#include <>#include <>#include <>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];/*ID*/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->,num)==0){printf("the train '%s'has been born!\n",num);return ;}s = s->next ;}p = (struct node*)malloc(sizeof(struct node));strcpy(p->,num);printf("Input the city where the train will reach:");scanf("%s",p->;printf("Input the time which the train take off:");scanf("%s",p->;printf("Input the time which the train receive:");scanf("%s",&p->;printf("Input the price of ticket:");scanf("%d",&p->;printf("Input the number of booked tickets:");scanf("%d",&p->;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->;printf(">>city the train will reach: %s\n",p->;printf(">>the time the train take off: %s\nthe time the train reach: %s\n",p->,p->;printf(">>the price of the ticket: %d\n",p->;printf(">>the number of booked tickets: %d\n",p->;}struct node * Locate1(Link l,char findmess[],char numorcity[]){Node*r ;if(strcmp(numorcity,"num")==0){r=l->next ;while(r){if(strcmp(r->,findmess)==0)return r ;r=r->next ;}}else if(strcmp(numorcity,"city")==0){r=l->next ;while(r){if(strcmp(r->,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->,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->,str2);printf("Input your bookNum: ");scanf("%d",&dem);h->=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->,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->;printf("Input new city the train will reach:");scanf("%s",&p->;printf("Input new time the train take off");scanf("%s",&p->;printf("Input new time the train reach:");scanf("%s",&p->;printf("Input new price of the ticket::");scanf("%d",&p->;printf("Input new number of people who have booked ticket:");scanf("%d",&p->;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->,str)==0&&r-><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("c:\\","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 savedis %d\n",count);shoudsave=0 ;}fclose(fp);}/*保存订票人的信息*/void SaveBookmanInfo(bookManLink k){FILE*fp ;bookMan*p ;int count=0,flag=1 ;fp=fopen("c:\\","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("c:\\","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("c:\\","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;}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#include<conio.h>#define N 1000typedefstruct TICKET //定义新结构体TICKET {char num[10]; //车次char hour[3];char min[3];char from[10];char to[10];float hours;int max; //车载容量int now; //已售票数}CLASS;int class_num=0;CLASS records[N];int system_time();void message();void ShowTable1();void ShowTable2(i nt i);void Display();void add();void save();void load(); // 按班次查询void search(); //查询void change(); //修改void quit(); //退出void buyticket(); //售票void deleteticket(); //取消int menu_select(); //菜单int whether(int); //判断购买时间void find(char s1[],char s2[]); //按起点终点查询void deletemessage(); //删除int findnum(char s1[]); //班次查询void get(int,int); //修改及增加班次char*menu[]={" 欢迎使用车票查询系统","\n*******************菜单***********************", "\n 1. 录入班次","\n 2. 浏览班次信息","\n 3. 查询路线","\n 4. 增加班次","\n 5. 售票","\n 6. 退票","\n 7. 修改班次","\n 8. 删除班次","\n 9. 退出"};int main(){system("cls");while(1){switch(menu_select()) //菜单{case 1: message();b reak;case 2: Display();b reak;case 3: search();b reak;case 4: add();break;case 5: buyticket();break;case 6: deleteticket();break;case 7: change();b reak;case 8: deletemessage();b reak;case 9: quit();break;}}}int menu_select() //菜单{char s[5];int c,i;system("cls");for(i=0;i<11;i++){printf("%s",menu[i]); //输出菜单}i=0;while(c<0||c>9){printf("\n");printf("\n请输入选项(1-9): ");scanf("%s",s);c=atoi(s);}//输出菜单return c;}void message() //录入{int i=0,j=5,h;char s[5];FILE *fp; //定义文件型指针变量system("cls"); //刷屏if((fp=fopen("d:车票管理系统0.dat","rb"))!=NULL) //fopen打开文件{printf("增加信息\n");printf("请输入任意键返回\n");scanf("%s",s);i=1;}if(i==0){system("cls"); //刷屏printf("请输入班次总数:\n");scanf("%d",&class_num); //指向班次指针system("cls"); //刷屏for(i=0;i<class_num;i++){system("cls"); //刷屏printf("请输入%d班次信息:\n",i+1);h=-1;for(;h!=i;) ///循环输出{printf("请输入班次:\n");scanf("%s",records[i].num);for(h=0;h<i;h++)if(strcmp(records[h].num,records[i].num)==0){printf("该班次已存在\n");break;}}get(i,j); //修改及增加班次j=5;}save(); //调用保存函数}}/*******************************显示所有函数********************************/void Display() //显示所有函数{int i,j;system("cls"); //刷屏load(); // 按班次查询ShowTable1();for(i=0,j=0;i<class_num;i++,j+=2) //按班次顺序输出{if(whether(i)) //判断时间是否超出printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min, records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);elseprintf("|%10s| 已发车|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);}ShowTable2(j);printf("\n按任意键继续\n");getch();}void ShowTable1(){int i=2;system("cls"); //刷屏printf(" 班次信息\n");printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");printf("\n| 班次| 发车时间| 起点站| 终点站|行车时间|额定载量| 已售票|\n");}void ShowTable2(i nt i){printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");}void search() //查询班次{int i;char s1[10]={'\0'},s2[10]={'\0'};system("cls"); //刷屏printf("1. 按班次查询\n");printf("2. 按终点站查询\n");printf("3. 退出\n");printf("请选择(1-3):\n");scanf("%d",&i);load(); //按班次查询switch(i){case 1: printf("请输入要查询的班次:\n");scanf("%s",s1);find(s1,s2);break;case 2: printf("请输入要查询终点站:\n");scanf("%s",s2);find(s1,s2);break;case 3: break;default : printf("输入错误!\n");break;}printf("按任意键继续\n");getch();}void find(char s1[],char s2[]){int i,h=0,m;ShowTable1();if(s2[0]=='\0')m=1;else m=0;for(i=0;i<class_num;i++)if(strcmp(s1,records[i].num)==0||strcmp(s2,records[i].to)==0){printf("\n");printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);h+=2;if(m==1)break;}ShowTable2(h);if(h==0)printf("查找的班次不存在\n");}void add(){int i,j=5;load();system("cls");printf("1. 增加班次\n");printf("2. 返回\n");printf("请选择(1-2)\n");scanf("%d",&i);if(i==1){system("cls");printf("1. 输入要增加的班次:\n");scanf("%s",records[class_num].num);for(i=0;i<class_num;i++)if(strcmp(records[class_num].num,records[i].num)==0){printf("输入错误\n");getch();break;}if(i==class_num){get(i,j);class_num++;save();}}}void buyticket(){int i;char num[10];system("cls");printf("1. 售票\n");printf("2. 返回\n");printf("请选择(1-2):\n");scanf("%d",&i);if(i==1){load(); // 按班次查询search();printf("请输入要订票的班次(若无请输入0):\n");scanf("%s",num);for(i=0;i<class_num;i++)if(strcmp(num,records[i].num)==0)if(records[i].max>records[i].now&&whether(i)==1){records[i].now++;printf("通向%s班次为%s的票订票成功\n",records[i].to,records[i].num);save();getch();break;}else{printf("该班次已满或已发出!\n");getch();}}}void deleteticket(){int i;char num[10];system("cls");printf("1. 退票\n");printf("2. 返回\n");printf("请选择(1-2)\n:");scanf("%d",&i);if(i==1){system("cls");load();printf("请输入要退票的班次:\n");scanf("%s",num);i=findnum(num);if(strcmp(num,records[i].num)==0)if(whether(i)){printf("是否确认");scanf("%s",num);if(num[0]=='y'||num[0]=='Y'){records[i].now--;printf("退票成功\n");save();getch();}}else{printf("该班车已发出,无法退票\n");getch();}if(i==class_num){printf("输入错误\n");getch();}}}void change(){char num[10],s[10];int h=0,j=13,i;load();system("cls");printf("请输入要修改的班次:\n");scanf("%s",num);i=findnum(num);if(i==class_num){printf("输入错误\n");getch();}else{printf("确认修改\n");scanf("%s",s);if(s[0]=='y'||s[0]=='Y'){get(i,j);save();}}}void deletemessage(){int i,h=0;char num[10];system("cls");printf("1. 删除班次\n");printf("2. 返回\n");printf("请选择(1-2):\n");scanf("%d",&i);if(i==1){system("cls");printf("请输入要删除的班次:\n");scanf("%s",num);i=findnum(num);if(i==class_num){printf("输入错误\n");getch();}else{printf("是否确认\n");scanf("%s",num);if(num[0]=='y'||num[0]=='Y'){for(;i<class_num-1;i++)records[i]=records[i+1];class_num--;save();printf("删除成功\n");getch();}}}}int findnum(char s1[]){int i,h=0;ShowTable1();for(i=0;i<class_num;i++){if(strcmp(s1,records[i].num)==0){printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[i].h our,records[i].min,records[i].from,records[i].to,records[i].hours,records[i].max,records[i] .now);h+=2;break;}}ShowTable2(h);return i;}void save(){FILE *fp1,*fp2;if((fp1=fopen("d:车票管理系统.dat","wb"))==NULL) //打开文件{printf("文件打开错误!\n");exit(0);}if((fp2=fopen("d:车票管理系统0.dat","wb"))==NULL){printf("文件打开错误!\n");exit(0);}fwrite(&class_num,sizeof(int),1,fp2);fwrite(records,sizeof(CLASS),class_num,fp1);fclose(fp1);fclose(fp2);}void load(){FILE *fp1,*fp2;if((fp1=fopen("d:车票管理系统.dat","rb"))==NULL){system("cls");printf("文件打开错误\n");getch();exit(0);}if((fp2=fopen("d:车票管理系统0.dat","rb"))==NULL){system("cls");printf("文件打开错误\n");getch();exit(0);}fread(&class_num,sizeof(int),1,fp2);fread(records,sizeof(CLASS),class_num,fp1);fclose(fp1);fclose(fp2);}void quit(){char s[5];printf("确认退出\n");scanf("%s",s);if(s[0]=='y'||s[0]=='Y')exit(0);}void get(int i,int j){for(;;){printf("请输入发车时间(xx xx)");scanf("%s%s",records[i].hour,records[i].min);if((atoi(records[i].hour)<24&&atoi(records[i].hour)>=0)&&(atoi(records[i].min)<60& &atoi(records[i].min)>=0))break;else{printf("输入错误\n");getch();}}printf("请输入起点站:\n");scanf("%s",records[i].from);printf("请输入终点站:\n");scanf("%s",records[i].to);printf("请输入行车时间:\n");scanf("%f",&records[i].hours);printf("请输入额定载量:\n");scanf("%d",&records[i].max);for(;;){printf("请输入已售票数:\n");scanf("%d",&records[i].now);if(records[i].now<=records[i].max)break;else{printf("输入错误\n");getch();}}}int whether(int i){struct tm *local;time_t t;t=time(NULL); //NULL在stdio.h中定义为0local=localtime(&t); /////获取当前系统时间if(local->tm_hour<atoi(records[i].hour)||local->tm_hour==atoi(records[i].hour)&&local->tm_min<atoi(records[i].min))//atoi将字符串转换成一个整数值return 1;elsereturn 0;}。