火车站售票查询系统 C语言 源代码

合集下载

列车时刻表信息管理系统实践报告C语言源代码

列车时刻表信息管理系统实践报告C语言源代码

t\t\t#include /z stdio. h〃 #include /z stdlib ・ h 〃 #include z/string. hV*定义头文件,处理文件及字符数组时要用到相应功能 #define N 10 void fmenu() (system(〃cls 〃); printf("************************ vl.20*****************\n 〃); 查询列车 %cl. */欢迎使用苏州列车时刻表信息管理系统 printf(〃\t\ \n\ 3) t\t\t printf (z/\n ,z %c2. 修改列车 \n\ 3)); printf (〃\t\ %c3. 增加列车\n\ 3) printf CW %c4. 取消列车 \n\ 3) ); printf("\t\ t\t\t printf C\n z/ ); , %c5. %c0. 保存信息 \n\ 3) r aX* f viz K I X K I Z K I X x/z K I Z K I ZI I printf (,z \ t\***********、□"); t\t\tprintf j ; if 选择要执行的操作:\n 〃);/*菜单程序,用于各种功能的选择*/ ' struct train/*定义结构体*/ ); phiiatfi4rn^fS]; t't'tchar checi[6];旺l 吁翦;yr ); tint month; printf (〃\t\int day; t\t\t int hour; int minute; } lieche[N] ;/* 定义一个结构体数组 */ void paixu(struct train *p) ;/* 函数声明 */ void chaxun(struct train *p)/*子程序,其功能是查询列车*/ ( paixu(lieche) ;/*先排序一下,方便查看*/ char a[8] ;/*定义一个字符数组,输入要查 询的列车 int k=0, i, c; */ printf ("请输入要查询的列车:\n 〃); scanf ("%s", a); for(i=0;i<N;i++)if (strcmp(p[i]・ name, a) ==0)printf (,z苏州一%s\t%s (车次)\t%d 年%d\t%d:%02d\n,\ p[i]・name, p[i]・checi, p[i]・year, p[i]・month, p_i]・day, p[i]・hour, p[i]・minute) ;/*车的信息全部打出*/k++;)if(k==0)printf (z/抱歉,没有这趟列车\n〃);/*没有查到时,打出通知*/ printf C按1继续,按0退出\『);/*选择继续或者退出*/ scanf(〃%d〃,&c);if(c!=0)chaxun(lieche);void xiugai (struct train *p)/*子程序,用于修改列车时间*/(char a[8], b [6];int i, x, c, k二0, h, mi, y, m, d, q;printf(〃请输入要修改的列车:\n〃);scanf ("%s", a);for(i=0;i<N;i++)(if (st rcmp (p[i ]・ name, a) =0)printf (z,苏州一%s\t%s ()车次\t%d 年%d\t%d:%02d\n,/, p[i]・ name, p[i]・ checi, p[i]. year, p[i]・ month, p.i]・ day, p[i]・ hour, p[i]・ minute)fprintf (”要修改这趟列车吗?\nl.是0.否\n〃);scanf &q); if (q==l)printf ("请输入修改后的车次:\n,z) ; scanf ("%s", b);printf ("请输入修改后的年月日:\n") ; scanf (“%d%d%d", &y, &m, &d);scanf ("%d%d〃, &h, &mi);printf C确定修改吗?\nl.是2.否\n〃);/*选择是否确定修改列车时%d日将所间,防止查列错误操作*/scan f ("%d〃,&x);if (x=l)(strcpy (p[i]・ checi, b); p[i]. yearly;%d日p[i]・ month二m; p[i]. day=d; p[i]・ hour=h; p[i]・ minute二mi; printfC己经修改此列车〃);k++;)} if(k==0)printf(z,抱歉,没有这趟列车\n〃);/*没有查到时,打出通知*/ printf C按]继续,按scanf &c) ;0 退出\n");if(c!=0)xiugai(lieche);void zengjia(struct train 子程序,用于列车增加*/*p) /*(struct train a;char 空白位置,在此处插入所填列车*/b □二{〃0000000〃} ;/*printf (〃请输入要增加的列车目的地:\『);scanf ("%s", a. name);printf(〃请输入修改后的车次:\rT);scanf a. checi);printf (〃请输入所增加列车的年月日:\『);scanf ("%d%d%d", &a. year, &a. month, &a. day);printf(〃请输入所增加列车的小时和分钟:\n〃);scanf ("%d%d", &a. hour, &a. minute);printf (”确定要增加这一趟列车吗?\nl.是0.否\n〃);scanf&x);if(x==l) for(i=0;i<N-l;i++)if (strcmp (p[i]・ name, b) =0)(strcpy (p[i]・ name, a. name) ; strcpy (p[ij. checi, a. checi);p[i]. year=a・ year;p[i]・ month=a・ month; p[i]・ day=a・ day; p[i]・ hour=a・ hour;p[i]・ minute=a・ minute;strcpy (pli+l]. name, b) ;/*找到位置,插入列车,并把0000000给后面一个结构体*/printfC已经增加这趟列车“);break;5 paixu(lieche) ; printf (〃按 1 继续,按0 退出\n") ; scanf ("%d", &c); if(c!=0) zengjia(lieche); } voidpaixu(struct train *p)/*子程序,用于同名列车时刻排序*/ int i, x; char a[6];for(i=0;i<N;i++)if (strcmp(p[i]. name, p[i+l]. name)==0)/* 先找到相同名字的列车*/ if (p[iJ. year>p[i+l]. year)// 根据年份排序(strcpy (a, p[i]・ checi);strcpy (p[i]・ checi, p[i+l]・ checi);strcpy(p[i+l]. checi, p[i[・ checi) ; x二p[i]・ year; p[i]・ year=p[i+l]. year;p[i+l]. year=x;x=p[i]・ month;p[i]・ month二p[i+l]・ month;p[i+l]・ month二x;x二p[i]. day;p[i]. day=p[i+l]. day;p[i+l]・ day=x;x二p[i]・ hour;p[i]・ hour二p[i+l]. hour;p[i+l]・ hour=x;x二p[i]. minute;p[i]. minute=p[i+l]・ minute;p[i+l]. minute二x;else if(pLi]・year二二p[i+l].year)if (p[i]. month>p[i+l]. month)// 相同年数,根据月份排序。

用C写得车票管理系统源码

用C写得车票管理系统源码

车票管理系统详细说明:1.程序功能一车站每天有n个发车班次,每个班次都有一班次号(1、2、3、…、n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。

如:班次发车时间起点站终点站行车时间额定载量已定票人数1 8:00 重庆昆明 10 45 302 6:30 重庆成都 4 40 403 7:00 重庆成都4 40 204 10:00 重庆成都 4 40 2……现要求设计一个管理系统,能完成如下功能:(1)录入班次信息(信息用文件保存),可不定时地增加班次数据;(2)浏览班次信息,可显示出所有班次当前状况(如果当前系统时间超过了某班次的发车时间,则显示"此班已发出"的提示信息);(3)查询路线:可按班次号查询,也可按终点站查询;(4)售票和退票功能。

①:当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数;②:退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数。

2.设计思想此系统可参照学生成绩管理系统的部份设计方法而设计。

1车票管理系统车票管理系统一车站每天有n个发车班次,每个班次都有一班次号(1、2、3…n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。

如班次发车时间起点站终点站行车时间额定载量已定票人数1 8:00 郫县广汉2 45 302 6:30 郫县成都0.5 40 403 7:00 郫县成都0.5 40 204 10:00 郫县成都0.5 40 2…(一)功能要求:用c/c++设计一系统,能提供下列服务:(1)录入班次信息(信息用文件保存),可不定时地增加班次数据(2)浏览班次信息,可显示出所有班次当前状态(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。

(3)查询路线:可按班次号查询,可按终点站查询(4)售票和退票功能A:当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数B:退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数(二)其它要求:(1) 只能使用C/C++语言,源程序要有适当的注释,使程序容易阅读(2) 至少采用文本菜单界面(如果能采用图形菜单界面更好)(3) 学生可自动增加新功能模块******************************************************************* ************************************************/ #include<stdio.h>#include<stdlib.h>#include<dos.h>#include<time.h>#include<conio.h>#include<string.h>const int MAX=20;const int N=50;const int MAXFILENAME=100; enum {FALSE,TRUE};struct time{int hour;int minutes;};struct ticket{int SerialNumber;struct time SetOut;char DeparturePoint[MAX];char TerminalPoint[MAX];float LastTime;int FixNumber;int FixedNumber;}car[N];int RecordNumber;int FLAG=FALSE;/**********************************************/ int ShowMessage(void); //载入原始数据void mainmenu(void); //主菜单void InsertMessage(void); //录入班次信息void SearchMenu(void); //查询路线子菜单void SearchByNumber(void); //按班次号查询void SearchByAddress(void); //按终点站查询void TicketManagement(void); //车票售出与退回void TicketOrder(void); //售票void TicketDelete(void); //退票void exit(void); //退出该系统/********************************************/ int main(void){RecordNumber=ShowMessage();if(1)do{mainmenu();}while(FLAG==FALSE);return 0;}void mainmenu(void){system("color 1f");system("mode con: cols=140 lines=130");char functionNumber;printf(" 车票管理系统\n\n");printf(" 制作:hmm182007\n");printf(" 日期:2007/11/25/19:57\n");printf("=========================================================== =============== ==\n");printf(" 1.录入班次信息\t\n");printf(" 2.浏览班次信息\t\n");printf(" 3.查询行车路线\t\n");printf(" 4.售票与退票系统\t\n");printf(" 5.退出该系统\t\n");printf("=========================================================== =============== ==\n");printf("请选择你所需要的功能:");scanf("%c",&functionNumber);switch(functionNumber){case '1':{InsertMessage();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '2':{ShowMessage();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '3':{SearchMenu();printf("\n按任意键回主菜单......\n"); getchar();getchar();}break;case '4':{TicketManagement();getchar();getchar();}break;case '5':FLAG=TRUE;exit();break;default:{printf("输入错误,请确保你的输入为1--5.\n"); printf("按任意键回主菜单......\n");getchar();getchar();}}//switch endsFLAG=FALSE;}void InsertMessage(void){FILE *fp;char filename[MAXFILENAME];int i;printf("请输入文件名或者文件路径名:");scanf("%s",filename);if((fp=fopen(filename,"r"))==NULL){printf("文件%s不可读,请确认文件%s存在或者文件路径正确.\n\n",filename,filename);mainmenu();}for(i=RecordNumber;!feof(fp)&&!ferror(fp);i++){fscanf(fp,"%d%d%d",&car[i].SerialNumber,&car[i].SetOut.hour,&car[i] .SetOut.minutes);fscanf(fp,"%s%s%f%d%d",&car[i].DeparturePoint,&car[i].TerminalPoint ,&car[i].LastTime,&car[i].FixNumb er,&car[i].FixedNumber);}int count=i;printf("班次\t发车时间\t起点\t终点\t行车时间(小时)\t额定载量\t已定票人数\n");for(i=0;i<count;i++){printf("%d\t%d:%d\t\t",car[i].SerialNumber,car[i].SetOut.hour,car[i ].SetOut.minutes);printf("%s\t%s\t\t%.1f\t%d\t\t%d\n",car[i].DeparturePoint,car[i].TerminalPoint,car[i].LastTime,c ar[i].FixNu mber,car[i].FixedNumber);}fclose(fp);}int ShowMessage(void){int i;FILE *fp;if((fp=fopen("add.txt","r"))==NULL){printf("读取数据失败,请检查文件add.txt是否存在.\n"); exit(-1);}for(i=0;!feof(fp)&&!ferror(fp);i++){。

火车票售票系统C语言大作业,基于C语言实现简单的12306火车售票系统

火车票售票系统C语言大作业,基于C语言实现简单的12306火车售票系统

⽕车票售票系统C语⾔⼤作业,基于C语⾔实现简单的12306⽕车售票系统程序设计要求⽤C语⾔写⼀个简单的⽕车售票系统,主要实现的功能为:录⼊班次信息浏览班次信息按班次号查询按终点站查询按余票数量排序保存售票退票更新班次信息退出系统所有的班次信息保存在number.dat⽂件中,排序过后的保存在sort.dat中(.dat是⼀种⼆进制⽂件)。

在编写的过程中我觉得在判断⽕车的状态⽐较值得深究。

这⾥假设⽕车主要有四种状态:1.未发车2.已发车3.停⽌检票4.停⽌退票在程序中,思路是将代表发车时间的字符串转化为整型,再和系统现在的时间进⾏⼤⼩⽐较,主要采⽤if判断各种情况。

其中atime代表的是发车时间的整型数,btime代表的是系统时间的整型数,具体实现如下:if(atime<=btime) //已经发车return 1;if(((atime-btime<=30)&&(atime-btime>5)&&(atime/100==btime/100))||(((atime%100+(60-btime%100))<=30)&&(atime%100+(60-btime%100))>5&&(atime/100-btime/100==1))) //距发车半⼩时以内,停⽌退票,%表⽰取余return 2;if(((atime-btime<=5)&&(atime/100==btime/100))||((atime%100+(60-btime%100)&&(atime/100-btime/100==1))<=5)) //距发车前五分钟内停⽌检票return 3;return 0; //可以办理购退票在判断退票时如果两个时间的⼩时数是⼀样的,则它们的分钟数如果相差在30之内即半⼩时之内或者发车时间的⼩时和系统时间的⼩时相差⼀个1,并且发车时间的分钟数⼩于30,系统时间的分钟⼤于30,则它们之间也就相差在30之内,此时代表停⽌退票。

C语言 车票管理系统源程序

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(&lt);printf(ctime(&lt));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语言编程---火车订票系统源代码

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语言设计火车票订票系统

软件课程设计--C 语言设计火车票订票系统之源代码模拟数据库功能需求分析可行性分析设计题目:火车订票系统小组成员:指导教师:完成时间:一.需求设计:1.每条线路所涉及的信息有:起点、终点、站名、车次、、票价、时间、座位号。

2.作为示意系统,全部数据可以只放在内存中。

3.系统能实现的功能和操作如下:①.查询路线:根据旅客提出的终点站名输入下列信息:车次、车站名。

②.承办订票业务:根据客户提出的要求查询该车次票额的情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新查询客户要求,若需要可登记排队候补。

③.承办退票业务:根据客户提供的情况(车次、时间、座位号)为客户办理退票手续,然后查询该车次是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户。

④登记旅客情况:包括旅客姓名,性别,年龄,家庭住址,联系方式等。

⑤统计功能:将每次车的订票,退票结果统计出来。

⑥管理功能:列车管理员可以通过调用函数来查看车票极其用户情况.⑦.查询功能:用户可以查询自己需要的车辆信息.二.总体设计1.程序流程图:按1键按2键按3键按4键进入in 函数进入book 函数进入inquire 函数进入cancel 函数按5键进入you 函数2.总体设计说明:①.数据结构设计:程序数据结构算法一个好的程序必定有一个好的数据结构.本设计主要考虑车票信息和用户信息的数据结构.车票信息采用半十字链表.横向链表中的每一个结点包含以下内容:车次起始站发车时间指向下一个结点的指针指向中途站的指针.纵向链表中每一个结点包含以下内容:从始发站开始的依次到站票价到达时间是否已被购买标识才用mark 标识当mark 为1 时车票已售出当mark 为0时车票还未售出.以及指向下一个结点的指针.纵向链表采用循环链表尾指针指向首指针.未购票用户信息使用队列来保存因为考虑到用户会预订票所以把用户以来订票的时间早晚排在队中.先来先买后来后买.队列中的每个元素包含以下内容:用户姓名身份证号码想要购票的车次起始站要到的站时间.已经购票用户信息使用一个单链表来保存链表中的没个结点包含以下内容:用户姓名身份证号码已购车票的车次出发时间到达时间.车票信息链表示意图:车次起始站发车时间downnnext下一站名到站时间票价marknext座位号未购票用户信息队列:用户姓名购票的车次起始站要到的站达到时间用户姓名购票的车次起始站要到的站达到时间注:座位号包含在车次号中已购票用户信息链表示意图:用户姓名身份证号码已购车票的车次号出发时间到达时间注:座位号包含在车次号中②算法的设计:主函数:利用case 语句实现用户界面,用户输入需要的服务的数字代码,程序就会转到相应的函数,实现相应的功能。

火车票查询系统代码

火车票查询系统代码

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));

火车售票系统完整代码

火车售票系统完整代码

package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.CallableStatement;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextArea;import javax.swing.JTextField;public class BuyPanel extends JPanel {StringBuffer sb = new StringBuffer();private boolean flag = false;JTextArea jtArea = new JTextArea(10, 78);JLabel buyLabel = new JLabel("订票");JTextField fId = new JTextField(7);JTextField ftid = new JTextField(7);JTextField fche = new JTextField(7);JTextField fzhangshu = new JTextField(7);JTextField fbodyId = new JTextField(7);JPasswordField jpField = new JPasswordField(7);public JPanel getBuypn() {JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100, GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(buyLabel, con);con = getGridBagConstraints(0, 2, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan3(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan4(), con);con = getGridBagConstraints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;}/*** 定义下面购票操作区面板pan3** @author Administrator**/class pan3 extends JPanel {JLabel lId = new JLabel(" 车票号码 ");JLabel ltid = new JLabel(" 车票号码 ");JLabel che = new JLabel(" 车次 ");JLabel lbodyId = new JLabel(" 身份证号 ");JLabel password = new JLabel(" 密码 ");JLabel lzhangshu = new JLabel(" 所需张数 ");JLabel la1 = new JLabel(" ");JLabel la2 = new JLabel(" ");JButton sureButton = new JButton("查询确认");JButton buyButton = new JButton("确认购票");public pan3() {buyButton.addActionListener(new ActionListener(){@Overridepublic void actionPerformed(ActionEvent e) {UpdateUser();if (flag==true){UpdateTrain();System.out.println("hjkasfhjkaf");}}});sureButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {select();}});GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100, GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fId, con);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(la2, con);con = getGridBagConstraints(9, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(sureButton, con);con = getGridBagConstraints(0, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(ltid, con);con = getGridBagConstraints(1, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(ftid, con);con = getGridBagConstraints(2, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(che, con);con = getGridBagConstraints(3, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fche, con);con = getGridBagConstraints(4, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lbodyId, con);con = getGridBagConstraints(5, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fbodyId, con);con = getGridBagConstraints(0, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(password, con);con = getGridBagConstraints(1, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jpField, con);con = getGridBagConstraints(2, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lzhangshu, con);con = getGridBagConstraints(3, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(fzhangshu, con);con = getGridBagConstraints(8, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(la1, con);con = getGridBagConstraints(9, 2, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(buyButton, con);this.setBorder(BorderFactory.createTitledBorder("订票操作区"));}}/*** 定义下面一个JList用于显示车票的所有信息面板pan4** @author Administrator**/class pan4 extends JPanel {JButton btId = new JButton("车票号码");JButton bt1 = new JButton("起点站");JButton bt2 = new JButton("终点站");JButton bt3 = new JButton("车次");JButton bt4 = new JButton("发车时间");JButton bt5 = new JButton("到达时间");JButton bt6 = new JButton("座位类型");JButton bt7 = new JButton("发车日期");JButton bt8 = new JButton("剩余票数");JButton bt9 = new JButton("车票价格");public pan4() {this.setLayout(new GridBagLayout());GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100, GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(btId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(2, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt2, con);con = getGridBagConstraints(3, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt3, con);con = getGridBagConstraints(4, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt4, con);con = getGridBagConstraints(5, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt5, con);con = getGridBagConstraints(6, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt6, con);con = getGridBagConstraints(7, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt7, con);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt8, con);con = getGridBagConstraints(9, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt9, con);con = getGridBagConstraints(0, 1, 11, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jtArea, con);jtArea.setBackground(Color.GREEN);}}/*** 定义最下面的按钮面板pan5** @author Administrator**/class pan5 extends JPanel {JButton bt1 = new JButton("退出登录");JLabel lab1 = new JLabel(" ");public pan5() {GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100, GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lab1, con);bt1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {System.exit(0);}});}}/*** 放回一个网格包约束** @param x* @param y* @param width* @param heigh* @param weighx* @param weighy* @param fill* @param anchor* @return*/private GridBagConstraints getGridBagConstraints(int x, int y, int width, int heigh, int weighx, int weighy, int fill, int anchor) { GridBagConstraints con = new GridBagConstraints();con.gridx = x;con.gridy = y;con.gridwidth = width;con.gridheight = heigh;con.weightx = weighx;con.weighty = weighy;con.fill = fill;con.anchor = anchor;return con;}/*** 按车票号码搜索所有的车票信息** @throws SQLException*/private void select() {Connection conn = null;Statement stmt = null;ResultSet ticket = null;try {conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "store", "store");} catch (SQLException e1) {e1.printStackTrace();}try {stmt = conn.createStatement();String text = "select * from train_table " + "where tid=" + "'"+ fId.getText() + "'";ticket = stmt.executeQuery(text);while (ticket.next()) {String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime");String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + fId.getText() + "\t"+ " " + starter + "\t"+ " " + reacher+ "\t"+ " " + ticketNumber + "\t" + startTime + "\t"+ endTime + "\t" + seatIdNumber + "\t" + busDate + "\t"+ ticketNum + "\t" + price + " " + "\n");}jtArea.setText(sb.toString());if (sb.length() > 0) {sb.delete(1, sb.length());} else {JOptionPane.showMessageDialog(new TestFrame(), "无此车!");}} catch (SQLException e) {} finally {if (ticket != null) {try {ticket.close();} catch (SQLException e) {e.printStackTrace();}}if (stmt != null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}/*** 订票时更新数据库中的车票表*/private void UpdateTrain() {String tId=ftid.getText();int num=0;if (fzhangshu.getText().length()>0){num=Integer.parseInt(fzhangshu.getText());}Connection conn = Getgbc.getconnect();CallableStatement cst = null;try {conn.setAutoCommit(false);cst = conn.prepareCall("call train_proc (?,?)");cst.setString(1, tId);cst.setInt(2, num);cst.execute();mit();} catch (SQLException e1) {try {conn.rollback();JOptionPane.showMessageDialog(new TestFrame(), "客户订票失败!");} catch (SQLException e2) {JOptionPane.showMessageDialog(new TestFrame(), "客户订票失败!");}} finally {if (cst != null) {try {cst.close();} catch (SQLException e1) {e1.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e1) {e1.printStackTrace();}}}}/*** 订票时更新数据库中的用户表*/private void UpdateUser() {String tId=ftid.getText();String bId=fbodyId.getText();String cID=fche.getText();String pwd=String.valueOf(jpField.getPassword());int num=0;if((bId.equals(EnterFrame.ID))&&(pwd.equals(EnterFrame.password))){ if(fzhangshu.getText().length()>0){num=Integer.parseInt(fzhangshu.getText());}Connection conn = Getgbc.getconnect();Statement cst = null;try {cst = conn.createStatement();cst.executeUpdate("insert into order_table(tid,id_number,t_num,trainsum)"+ " values('"+ tId+ "','"+ bId+ "','"+ cID + "','"+num+"')");JOptionPane.showMessageDialog(new TestFrame(), "客户订票成功!");flag=true;} catch (SQLException e1) {JOptionPane.showMessageDialog(new TestFrame(), "订票失败!");flag=false;} finally {if (cst != null) {try {cst.close();} catch (SQLException e1) {e1.printStackTrace();}}if (conn != null) {try {conn.close();} catch (SQLException e1) {e1.printStackTrace();}}}}else{JOptionPane.showMessageDialog(new TestFrame(), "您的身份证或密码有误!请查证后再订票");}}}package com.yue;import java.awt.Color;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;public class CheckPanel extends JPanel {StringBuffer sb = new StringBuffer();JTextField trainField = new JTextField(9);JTextField dateField = new JTextField(9);JTextField stationField = new JTextField(9);JTextField zhiField = new JTextField(9);JTextArea jtArea = new JTextArea(10, 80);JLabel checkLabel = new JLabel("查询");public JPanel getCheckpn() {JPanel pan = new JPanel();GridBagLayout layout = new GridBagLayout();pan.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(checkLabel, con);con = getGridBagConstraints(0, 1, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan2(), con);con = getGridBagConstraints(0, 3, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);pan.add(new pan4(), con);con = getGridBagConstraints(0, 4, 1, 1, 100, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);pan.add(new pan5(), con);this.setLocation(270, 150);this.add(pan);return pan;}/*** 定义上部查询区面pan2** @author Administrator**/class pan2 extends JPanel {JLabel trainLabel = new JLabel(" 车次 ");JLabel dateLabel = new JLabel(" 日期 ");JLabel stationLabel = new JLabel(" 起点站 ");JLabel zhiLabel = new JLabel(" 终点站 ");JLabel l1 = new JLabel(" ");JLabel l2 = new JLabel(" ");JButton checkButton = new JButton("查询");JButton flushButton = new JButton("清空");JPanel panel1 = new JPanel();JPanel panel2 = new JPanel();JTextArea area = new JTextArea();public pan2() {flushButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {trainField.setText(null);stationField.setText(null);zhiField.setText(null);dateField.setText(null);jtArea.setText(null);}});checkButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {if (dateField.getText().trim().length() > 0) {if (trainField.getText().trim().length() > 0|| stationField.getText().trim().length() > 0|| zhiField.getText().trim().length() > 0) {jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置");} else {try {dateSelect();} catch (SQLException e1) {e1.printStackTrace();}}} else if (trainField.getText().trim().length() > 0) { if (dateField.getText().trim().length() > 0|| stationField.getText().trim().length() > 0|| zhiField.getText().trim().length() > 0) {jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置");} else {try {idSelect();} catch (SQLException e1) {e1.printStackTrace();}}} else if (stationField.getText().trim().length() > 0&& zhiField.getText().trim().length() > 0) {if (dateField.getText().trim().length() > 0|| trainField.getText().trim().length() > 0) { jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置");} else {try {stationSelect();} catch (SQLException e1) {e1.printStackTrace();}}} else if (dateField.getText().trim().length() <= 0&& stationField.getText().trim().length() <= 0&& zhiField.getText().trim().length() <= 0) {if (dateField.getText().trim().length() > 0|| stationField.getText().trim().length() > 0|| zhiField.getText().trim().length() > 0) {jtArea.setText(null);JOptionPane.showMessageDialog(new TestFrame(),"输入有误,请检查输入位置");} else {try {allSelect();} catch (SQLException e1) {e1.printStackTrace();}}}}});JPanel panel3 = new JPanel(new GridBagLayout());panel1.setBorder(BorderFactory.createTitledBorder("查询区"));panel2.setBorder(BorderFactory.createTitledBorder("售票注意事项"));area.setText("每人每次最多可够买十张火车票,超过十张火车票数的" + "\n"+ "请一定要出示您的相关的证件,一旦经过售票员查" + "\n" + "询核实并且同意后方可购买");panel2.add(area);GridBagLayout layout = new GridBagLayout();panel1.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(trainLabel, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(trainField, con);con = getGridBagConstraints(2, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(dateLabel, con);con = getGridBagConstraints(3, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(dateField, con);con = getGridBagConstraints(4, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(l1, con);con = getGridBagConstraints(5, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(flushButton, con);con = getGridBagConstraints(0, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(stationLabel, con);con = getGridBagConstraints(1, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(stationField, con);con = getGridBagConstraints(2, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(zhiLabel, con);con = getGridBagConstraints(3, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(zhiField, con);con = getGridBagConstraints(4, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(l2, con);con = getGridBagConstraints(5, 1, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel1.add(checkButton, con);con = getGridBagConstraints(0, 0, 6, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.WEST);panel3.add(panel1, con);con = getGridBagConstraints(6, 0, 2, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);panel3.add(panel2, con);this.add(panel3);}}/*** 定义下面一个JList用于显示车票的所有信息面板pan4** @author Administrator**/class pan4 extends JPanel {JButton btId = new JButton("车票号码");JButton bt1 = new JButton("起点站");JButton bt2 = new JButton("终点站");JButton bt3 = new JButton("车次");JButton bt4 = new JButton("发车时间");JButton bt5 = new JButton("到达时间");JButton bt6 = new JButton("座位类型");JButton bt7 = new JButton("发车日期");JButton bt8 = new JButton("剩余票数");JButton bt9 = new JButton("车票价格");public pan4() {this.setLayout(new GridBagLayout());GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100, GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(btId, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(2, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt2, con);con = getGridBagConstraints(3, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt3, con);con = getGridBagConstraints(4, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt4, con);con = getGridBagConstraints(5, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt5, con);con = getGridBagConstraints(6, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt6, con);con = getGridBagConstraints(7, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt7, con);con = getGridBagConstraints(8, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt8, con);con = getGridBagConstraints(9, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt9, con);con = getGridBagConstraints(0, 1, 11, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(jtArea, con);jtArea.setBackground(Color.CYAN);}}/*** 定义最下面的按钮面板pan5** @author Administrator**/class pan5 extends JPanel {JButton bt1 = new JButton("退出登录");JLabel lab1 = new JLabel(" ");public pan5() {bt1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {System.exit(0);}});GridBagLayout layout = new GridBagLayout();this.setLayout(layout);GridBagConstraints con = getGridBagConstraints(0, 0, 1, 1, 0, 100, GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(bt1, con);con = getGridBagConstraints(1, 0, 1, 1, 0, 100,GridBagConstraints.NONE, GridBagConstraints.EAST);this.add(lab1, con);}}/*** 放回一个网格包约束** @param x* @param y* @param width* @param heigh* @param weighx* @param weighy* @param fill* @param anchor* @return*/private GridBagConstraints getGridBagConstraints(int x, int y, int width, int heigh, int weighx, int weighy, int fill, int anchor) { GridBagConstraints con = new GridBagConstraints();con.gridx = x;con.gridy = y;con.gridwidth = width;con.gridheight = heigh;con.weightx = weighx;con.weighty = weighy;con.fill = fill;con.anchor = anchor;return con;}/*** 按初始站至终点站搜索车票** @throws SQLException*/private void stationSelect() throws SQLException {Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "store", "store");Statement stmt = conn.createStatement();String sqlText = "select tid,starter,reacher,ticketNumber,startTime,endTime,seatIdNumber,busDate,ticketN um,price from train_table where starter='"+ stationField.getText()+ "' and reacher='"+ zhiField.getText() + "'";ResultSet ticket = stmt.executeQuery(sqlText);while (ticket.next()) {int tid = ticket.getInt("tid");String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime");String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + tid + "\t" + starter + "\t" + reacher + "\t"+ ticketNumber + "\t" + startTime + "\t" + endTime + "\t"+ seatIdNumber + "\t" + busDate + "\t" + " " + ticketNum + "\t"+ " "+ price + " " + "\n");}jtArea.setText(sb.toString());if (sb.length() > 0) {sb.delete(1, sb.length());}else {JOptionPane.showMessageDialog(new TestFrame(), "无此车!");}ticket.close();stmt.close();conn.close();}/*** 搜索所有的车票信息** @throws SQLException*/private void allSelect() throws SQLException {Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "store", "store");Statement stmt = conn.createStatement();String text = "select * from train_table ";ResultSet ticket = stmt.executeQuery(text);while (ticket.next()) {int tid = ticket.getInt("tid");String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime");String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + tid + "\t" + starter + "\t" + reacher + "\t"+ ticketNumber + "\t" + startTime + "\t" + endTime + "\t"+ seatIdNumber + "\t" + busDate + "\t" + " "+ ticketNum + "\t"+ " "+ price + " " + "\n");}jtArea.setText(sb.toString());if (sb.length() > 0) {sb.delete(1, sb.length());}else {JOptionPane.showMessageDialog(new TestFrame(), "今天没车!");}ticket.close();stmt.close();conn.close();}/*** 按日期搜索所有的车票信息** @throws SQLException*/private void dateSelect() throws SQLException {Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCL", "store", "store");Statement stmt = conn.createStatement();String text = "select * from train_table where busDate='"+ dateField.getText() + "'";ResultSet ticket = stmt.executeQuery(text);while (ticket.next()) {int tid = ticket.getInt("tid");String starter = ticket.getString("starter");String reacher = ticket.getString("reacher");String ticketNumber = ticket.getString("ticketNumber");String startTime = ticket.getString("startTime");String endTime = ticket.getString("endTime");String seatIdNumber = ticket.getString("seatIdNumber");String busDate = ticket.getString("busDate");int ticketNum = ticket.getInt("ticketNum");double price = ticket.getDouble("price");sb.append(" " + tid + "\t" + starter + "\t" + reacher + "\t"+ ticketNumber + "\t" + startTime + "\t" + endTime + "\t"+ seatIdNumber + "\t" + busDate + "\t" + " "+ ticketNum + "\t"+ " "+ price + " " + "\n");}jtArea.setText(sb.toString());if (sb.length() > 0) {sb.delete(1, sb.length());}else {JOptionPane.showMessageDialog(new TestFrame(), "没车!");}ticket.close();stmt.close();conn.close();}/*** 按车次搜索所有的车票信息*。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*站点集合*/
char my_start_site[20]=""; /*输入的始发站*/
char my_end_site[20]="[6]=""; /*输入的到达时间*/
int all_length=0;
void _duration(char time1[6],char time2[6],char duration_time[6])
_time_to_2_numbers(time2,n1,n2); /*得到m1,m2 第二个时间的小时¡分钟*/
d1=m1-f1; /*小时的差值*/
if (m2>=f2)
d2=m2-f2; /*分钟的差值*/
else
{
d2=m2+60-f2;
d1=d1-1;
}
duration_time[0]='0'; duration_time[1]=d1+48; duration_time[2]=d2/10+48; duration_time[3]=d2%10+48; duration_time[4]='\0'; }
t21=a[2]-48;
t22=a[3]-48;
*p2=t21*10+t22; /*t2:后两位*/
}
TRAIN my[100]; /*存放:直达直达或者不能直达时前一段车次*/
TRAIN change[100]; /*存放:转车的车次*/
char site[7][20]={"Delphinium","Javaville","Oopcentral","Perlston","Seatown","Teakall"};
Journey Planer 原始程序
#define TRAIN struct journey /*#define _CRT_SECURE_NO_DEPRECATE*/ #include <stdlib.h> #include <stdio.h> #include <tchar.h> #include <string.h> #include <conio.h>
2
};
void _time_to_2_numbers(char a[6],int *p1,int *p2) /*字符串---- 数字,指针带回小时和分钟两个整*/
{
int t11,t12,t21,t22;
t11=a[0]-48; /*将'2'*字符转换为数字2*/
t12=a[1]-48;
*p1=t11*10+t12; /*t1:前两位*/
1
"Seatown" ,"Delphinium" ,"0845", "1046",\ "Seatown" ,"Delphinium" ,"1045", "1246",\ "Seatown" ,"Delphinium" ,"1145", "1347",\ "Seatown" ,"Delphinium" ,"1245", "1447",\ "Seatown" ,"Delphinium" ,"1445", "1647",\ "Seatown" ,"Javaville" ,"0830", "1007",\ "Seatown" ,"Javaville" ,"0930", "1107",\ "Seatown" ,"Javaville" ,"1000", "1136",\ "Seatown" ,"Javaville" ,"1039", "1155",\ "Seatown" ,"Javaville" ,"1100", "1231",\ "Seatown" ,"Javaville" ,"1230", "1354",\ "Seatown" ,"Javaville" ,"1330", "1453",\ "Seatown" ,"Javaville" ,"1509", "1642",\ "Seatown" ,"Oopcentral" ,"0905", "1338",\ "Seatown" ,"Oopcentral" ,"1104", "1532",\ "Seatown" ,"Oopcentral" ,"1334", "1909",\ "Seatown" ,"Oopcentral" ,"1445", "1956",\ "Seatown" ,"Perlston" ,"0836", "0930",\ "Seatown" ,"Perlston" ,"0936", "1030",\ "Seatown" ,"Perlston" ,"1036", "1130",\ "Seatown" ,"Perlston" ,"1136", "1230",\ "Seatown" ,"Perlston" ,"1236", "1330",\ "Seatown" ,"Perlston" ,"1336", "1430",\ "Seatown" ,"Perlston" ,"1436", "1530",\ "Seatown" ,"Teakall" ,"0800", "0945",\ "Seatown" ,"Teakall" ,"0835", "1017",\ "Seatown" ,"Teakall" ,"0934", "1120",\ "Seatown" ,"Teakall" ,"1034", "1216",\ "Seatown" ,"Teakall" ,"1107", "1302",\ "Seatown" ,"Teakall" ,"1134", "1326",\ "Seatown" ,"Teakall" ,"1234", "1417",\ "Seatown" ,"Teakall" ,"1334", "1519",\ "Seatown" ,"Teakall" ,"1434", "1616",\ "Teakall" ,"Delphinium" ,"0833", "0933",\ "Teakall" ,"Delphinium" ,"0933", "1033",\ "Teakall" ,"Delphinium" ,"1033", "1133",\ "Teakall" ,"Delphinium" ,"1133", "1233",\ "Teakall" ,"Delphinium" ,"1233", "1333",\ "Teakall" ,"Delphinium" ,"1333", "1433",\ "Teakall" ,"Delphinium" ,"1433", "1533",\ "Teakall" ,"Delphinium" ,"1533", "1633",\ "Teakall" ,"Javaville" ,"1103", "1429",\ "Teakall" ,"Javaville" ,"1115", "1445",\ "Teakall" ,"Javaville" ,"1217", "1542",\ "Teakall" ,"Javaville" ,"1517", "1846",\ "Teakall" ,"Oopcentral" ,"1307", "1628",\ "Teakall" ,"Oopcentral" ,"1522", "1909",\ "Teakall" ,"Seatown" ,"0814", "1003",\ "Teakall" ,"Seatown" ,"0914", "1100",\ "Teakall" ,"Seatown" ,"1014", "1159",\ "Teakall" ,"Seatown" ,"1115", "1303",\ "Teakall" ,"Seatown" ,"1217", "1403",\ "Teakall" ,"Seatown" ,"1314", "1451",\ "Teakall" ,"Seatown" ,"1417", "1600",\ "#","#","#","#"
相关文档
最新文档