火车站售票查询系统 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写得车票管理系统源码
车票管理系统详细说明: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语⾔写⼀个简单的⽕车售票系统,主要实现的功能为:录⼊班次信息浏览班次信息按班次号查询按终点站查询按余票数量排序保存售票退票更新班次信息退出系统所有的班次信息保存在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语言 车票管理系统源程序
#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.系统能实现的功能和操作如下:①.查询路线:根据旅客提出的终点站名输入下列信息:车次、车站名。
②.承办订票业务:根据客户提出的要求查询该车次票额的情况,若尚有余票,则为客户办理订票手续,输出座位号;若已满员或余票额少于订票额,则需重新查询客户要求,若需要可登记排队候补。
③.承办退票业务:根据客户提供的情况(车次、时间、座位号)为客户办理退票手续,然后查询该车次是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他办理订票手续,否则依次询问其他排队候补的客户。
④登记旅客情况:包括旅客姓名,性别,年龄,家庭住址,联系方式等。
⑤统计功能:将每次车的订票,退票结果统计出来。
⑥管理功能:列车管理员可以通过调用函数来查看车票极其用户情况.⑦.查询功能:用户可以查询自己需要的车辆信息.二.总体设计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();}/*** 按车次搜索所有的车票信息*。
火车票售票系统源代码
public void actionPerformed(ActionEvent e){
JFileChooser openfile = new JFileChooser();
p2.add(jtf4);
p2.add(jlb6);
p2.add(jtf5);
p2.add(jlb7);
p2.add(jtf6);
p2.add(jbt1);
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);
inputfile = new FileInputStream(filename);
int len = 0;
// 如下为依次读取文件中的每一行内容,将其加入StringBuffer数据类型便利strBF中
FileReader in = new FileReader(filename.getAbsoluteFile());
JLabel jlb5=new JLabel(" 身份证号");
JLabel jlb6=new JLabel(" 工作");
JLabel jlb7=new JLabel(" 电话");
final JTextField jtf1=new JTextField(10);
final JTextField jtf2=new JTextField(10);
JOptionPane.showMessageDialog(panel, error_message
);
火车票务管理系统(C语言)
火车票务管理系统一、课题内容和要求设计目标:设计一个火车票务管理系统,用C语言实现。
对该系统的要求如下:需求描述:1.系统功能(1)火车时刻信息录入。
包括车次、日期、起点、终点、开车时间、到达时间、票价。
数据存入数据文件hchsk.dat或hchsk.txt中。
(2)火车时刻信息查询。
按照车次查询按终点查询按起点查询按终点和日期查询(3)统计按终点统计每日的车次数按起点统计每日的车次数2. 系统主界面应有以下功能选项录入火车时刻信息查询火车时刻信息统计火车车次退出注:建议用VC环境开发用户界面。
结果形式:提交程序设计报告和可演示的系统软件二、需求分析系统主界面应有以下功能选项1.录入火车时刻信息2.查询火车时刻信息3.统计火车车次4.退出(1)火车时刻信息录入。
包括车次、日期、起点、终点、开车时间、到达时间、票价。
数据存入数据文件hchsk.dat或hchsk.txt中。
(2)火车时刻信息查询。
按照车次查询按终点查询按起点查询按终点和日期查询(3)统计按终点统计每日的车次数按起点统计每日的车次数二、概要设计void SearchTrainNum();//按照车次查询void SearchToPlace();//按终点查询void SearchFromPlace();//按起点查询void SearchToPlaceAndDate();//按终点和日期查询void CountToPlace();//按终点统计每日的车次数void CountFromPlace();//按起点统计每日的车次数三、详细设计程序的源代码与注释#include<stdio.h>#include<string.h>#include<stdlib.h>void SearchTrainNum();void SearchToPlace();void SearchFromPlace();void SearchToPlaceAndDate();void CountToPlace();void CountFromPlace();void Star();struct TRAIN{char trainNum[10];char date[30];char fromPlace[20];char toPlace[20];char inTime[30];char outTime[30];double price;};struct TRAIN train[30];int main(){int request;char ch='Y';int i=0;double myprice;FILE *fp;repeat:Star();printf("火车管理系统界面\n");printf("1.录入火车时刻信息.\n");printf("2.查询火车时刻信息.\n");printf("3.统计火车车次.\n");printf("4.退出.\n");Star();printf("\n");printf("请输入:");scanf("%d",&request);switch(request) //利用case分支结构{case 1:{ fp=fopen(".\\train.rec","wb"); //利用文件与流if(!fp){printf("File can not be opened\n");exit(1);}do{printf("Enter车次日期起点终点开车时间到达时间票价\n>>> ");scanf("%s%s%s%s%s%s%lf",train[i].trainNum,train[i].date,train[i].fromPlace ,train[i].toPlace,train[i].inTime,train[i].outTime,&myprice);train[i].price=myprice;fwrite(&train[i],sizeof(struct TRAIN),1,fp);i++;printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');fclose(fp);printf("返回主界面吗?(Y返回)");getchar();scanf("%c",&ch);if(ch=='Y'){printf("\n\n");goto repeat;}}break;case 2:{ printf("\n\n");printf(">>>>>火车时刻信息查询<<<<<\n");printf("1.按车次查询.\n");printf("2.按终点查询.\n");printf("3.按起点查询.\n");printf("4.按终点和日期查询.\n");printf("5.退出.\n");printf("请输入:");scanf("%d",&request);switch(request){case 1: SearchTrainNum(); break; case 2: SearchToPlace(); break;case 3: SearchFromPlace(); break; case 4: SearchToPlaceAndDate(); break; case 5: exit(0); break;}printf("返回主界面吗?(Y返回)");getchar();scanf("%c",&ch);if(ch=='Y'){printf("\n\n");goto repeat;}} break;case 3:{printf("\n\n");printf(">>>>>火车车次统计系统<<<<<\n");printf("1.按终点统计每日的车次数.\n");printf("2.按起点统计每日的车次数.\n");printf("3.退出.\n");printf("请输入:");scanf("%d",&request);switch(request){case 1: CountToPlace(); break;case 2: CountFromPlace(); break;case 3: exit(0); break;}printf("返回主界面吗?(Y返回)");getchar();scanf("%c",&ch);if(ch=='Y'){printf("\n\n");goto repeat;}} break;case 4:{Star();printf("欢迎下次使用,拜拜~~\n"); Star();}exit(0); break;default:printf("Incorrect num entered.");printf("Enter a new num.\n");break;}return 0;}void SearchTrainNum(){FILE *fp1;char num[20];char ch;int i=0;fp1=fopen(".\\train.rec","r+");if(!fp1){printf("File can not be opened\n");exit(1);}do{rewind(fp1); //文件指针的操作,到文件头部函数printf("输入你要查找的车次号.\n>>>");scanf("%s",num);while(!feof(fp1)){fread(&train[i],sizeof(struct TRAIN),1,fp1);if(strcmp(num,train[i].trainNum)==0){printf("%-4s%-12s%-8s%-10s%-10s%-8s%.2lf",train[i].trainNum,train[i].date, train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf("\n");}i++;}printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');printf("\n");fclose(fp1);}void SearchToPlace(){FILE *fp2;char num[20];char ch;int i=0;fp2=fopen(".\\train.rec","r+");if(!fp2){printf("File can not be opened\n");exit(1);}do{rewind(fp2);printf("输入你要查询的终点.\n>>>");scanf("%s",num);while(!feof(fp2)){fread(&train[i],sizeof(struct TRAIN),1,fp2);if(strcmp(num,train[i].toPlace)==0){printf("%-4s%-12s%-8s%-10s%-10s%-8s%.2lf",train[i].trainNum,train[i].date, train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf("\n");}i++;}printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');printf("\n");fclose(fp2);}void SearchFromPlace(){FILE *fp3;char num[20];char ch;int i=0;fp3=fopen(".\\train.rec","r+");if(!fp3){printf("File can not be opened\n");exit(1);}do{rewind(fp3);printf("输入你要查询的起点.\n>>>");scanf("%s",num);while(!feof(fp3)){fread(&train[i],sizeof(struct TRAIN),1,fp3);if(strcmp(num,train[i].fromPlace)==0){printf("%-4s%-12s%-8s%-10s%-10s%-8s%.2lf",train[i].trainNum,train[i].date,tra in[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price);printf("\n");}i++;}printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');printf("\n");fclose(fp3);}void SearchToPlaceAndDate(){FILE *fp4;char num[20];char num1[20];char ch;int i=0;fp4=fopen(".\\train.rec","r+");if(!fp4){printf("File can not be opened\n");exit(1);}do{rewind(fp4);printf("输入你要查询的终点与日期.\n>>>");scanf("%s",num);scanf("%s",num1);while(!feof(fp4)){fread(&train[i],sizeof(struct TRAIN),1,fp4);if((strcmp(num,train[i].toPlace)==0)&&(strcmp(num1,train[i].date)==0)) {printf("%-4s%-12s%-8s%-10s%-10s%-8s%.2lf",train[i].trainNum,train[i].date, train[i].fromPlace,train[i].toPlace,train[i].inTime,train[i].outTime,train[i].price); printf("\n");}i++;}printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');printf("\n");fclose(fp4);}void CountToPlace(){FILE *fp5;char num[20];char ch;int i=0;int j=0;fp5=fopen(".\\train.rec","r+");if(!fp5){printf("File can not be opened\n");exit(1);}do{rewind(fp5);printf("输入你(要统计的车次数的)终点.\n>>>");scanf("%s",num);j=0;while(!feof(fp5)){fread(&train[i],sizeof(struct TRAIN),1,fp5);if(strcmp(num,train[i].toPlace)==0){j++;}i++;}printf("当日终点%s的车次数:%d",num,j);printf("\n");printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');fclose(fp5);}void CountFromPlace(){FILE *fp6;char num[20];char ch;int i=0;int j=0;fp6=fopen(".\\train.rec","r+");if(!fp6){printf("File can not be opened\n");exit(1);}do{rewind(fp6);printf("输入你(要统计的车次数的)起点.\n>>>");scanf("%s",num);j=0;while(!feof(fp6)){fread(&train[i],sizeof(struct TRAIN),1,fp6);if(strcmp(num,train[i].fromPlace)==0){j++;}i++;}printf("当日起点%s的车次数:%d",num,j);printf("\n");printf("continue(Y/N)(N to end)?");getchar();scanf("%c",&ch);}while(ch!='N');fclose(fp6);}void Star(){int i;for(i=0;i<20;i++){printf("*");}printf("\n");}四、测试数据及其结果分析(如图)1.火车时刻信息录入2.火车时刻信息查询。
C语言--火车站售票系统报告及代码解析
目录第一章——————————————课程认识第二章——————————————课题选择第三章———————————总体设计与分析第四章————————————模块详细设计第五章————————————主要实现方法第六章————————————课程设计总结第七章————————————————结论第八章————————————————建议一、课程的性质、任务、目的C语言是非常优秀的程序设计语言,应用广泛,是高校计算机专业的一门专业基础课程;学好C语言,是学习计算机专业课程和用好计算机的重要基础。
要学好C语言,应抓好理论学习、上机实验以及综合应用这三个环节。
在《C程序设计》课程的学习中,学生在掌握C语言理论知识的同时,通过上机实验完成一定量的实践性题目,初步掌握了程序设计的基本思想、基本概念和基本方法。
本课程是计算机专业的学生在完成了《C程序设计》课程的学习后,为加强学生对程序设计思想的理解、通过解决有一定代表性的小型综合应用类课题从而提高实际编程能力而设置的一门实践性课程。
本课程为学生提供了一个既动手又动脑,独立实践的机会,将课本上的理论知识和实际有机地结合起来,培养和锻炼学生分工协作、分析和解决实际问题并利用计算机求解问题的能力,以提高学生适应实际,实践编程的能力,从而掌握基本的程序设计过程和技巧,具备初步的高级语言程序设计和调试能力。
二、课题选择(背景、意义、实用性……);背景:现今,人们的生活水平渐渐改善,生活质量也随之提高,人们的精神需求也大了,应此,出行旅游,或是走访亲友成了习以为常的事了,出行已成为现代人的家常便饭,汽车,火车,飞机等交通工具为我们提供了更多的方便。
然而在售票中,就需要一个售票系统来帮助售票员来更为快捷,高效,方便的售票,同时也为了车站方面更好的管理票务,因此,一个好的车票管理系统就必不可少了。
意义:选择车站售票系统作为课程设计的课题,就车站的售票流程等进一步了解车站的售票系统的原理。
车票管理系统C源代码
#include<stdio.h> ///宏定义函数#include<string.h> //串操作及内存操作函数#include<stdlib.h> /////调用系统函数#include<time.h> ///时间库函数#include<conio.h> ///输入输出函数#define N 1000 //宏定义多条记录typedef struct 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; ///初始班次总数为0CLASS records[N]; // 多条记录int system_time(); //系统时间void NewMessage(); //新纪录*录入函数******void ShowTable1(); //线框调用1,,,不用没次输void ShowTable2(int i); //线框调用2,,,不用没次输void Display(); //显示所有函数void add(); //增加记录void save(); // 保存函数void load(); // 按班次查询函数void search(); //查询函数void change(); //修改函数**void quit(); ////////// //退出函数******void Ticketorder(); // //*售票函数***void Ticketdelete(); //删除函数*int menu_select(); //菜单函数*int whether(int); ////判断时间是否超出函数***void find(char s1[],char s2[]); //查询函数★//s1为班次//s2为终点站void deletemessage(); //删除函数int findnum(char s1[]); //班次查询函数void get(int,int); //修改及增加班次*char *menu[]={"*****************欢迎使用车票查询系统*****************", "\n*******************MENU功能菜单***********************","\n◤★ 1. 录入班次◥","\n◆★ 2. 显示所有班次◆","\n◆★ 3. 查询班次◆","\n◆★ 4. 增加班次◆","\n◆★ 5. 售票◆","\n◆★ 6. 退票◆","\n◆★ 7. 修改班次◆","\n◆★ 8. 删除班次◆","\n◣★ 9. 退出◢"}; /**************************主函数***************************/void main(){system("cls"); //刷屏while(1) //菜单函数循环{switch(menu_select()) //菜单函数*{case 1: NewMessage();break; ////新纪录*录入函数******case 2: Display();break; // //显示case 3: search();break; //查找函数**case 4: add();break; // //增加记录case 5: Ticketorder();break; ////*售票函数***case 6: Ticketdelete();break; //删除函数*case 7: change();break; //修改函数**case 8: deletemessage();break; //////选择调用删除函数case 9: quit();break; //////退出函数******}}}/***********************菜单函数**************************/int menu_select() /////////菜单函数*{char s[5]; ///定义要输入的数字功能int c,i;system("cls"); //刷屏system("color 09");//改变颜色for(i=0;i<11;i++){printf("%s",menu[i]); //输出菜单各项)}i=0;while(c<0||c>9) //判断是否是1到9的命令{printf("\n"); ///输出换行printf("******************************************************");printf("\n请选择(1-9):▁▂▃▄▆▇");scanf("%s",s);c=atoi(s); //atoi将字符串转换成一个整数值} ///输出菜单面return c; ////返回请求}/*******************************录入函数************************************/void NewMessage() //*录入函数******{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; //通过是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(); //线框调用1,,,不用没次输for(i=0,j=0;i<class_num;i++,j+=2) /////按班次顺序输出{printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");if(whether(i)) //判断时间是否超出函数***printf("|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|",records[i].num,records[ i].hour,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); //线框调用2printf("\n按任意键继续....\n");getch(); /////从控制台读取一个字符,但不显示在屏幕上}/**********************************打印表头***********************************************/void ShowTable1() //线框调用1,,,不用没次输{int i=2;system("cls"); //刷屏printf("**************************MESSAGE车程信息**********************************\n");printf("\n|----------|----------|----------|----------|--------|--------|--------|\n");printf("\n| 班次 | 发车时间 | 起点站 | 终点站 |行车时间|额定载量| 已售票 |\n");}/***************************************打印表尾************************************************/void ShowTable2(int i) //线框调用2。
火车票售票系统(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;}。
火车售票系统完整代码
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();}/*** 按车次搜索所有的车票信息*。
VC车站票务管理系统(C语言(liunx))(SQLlite)
VC++062车站票务管理系统(C语言(liunx))(SQLlite)摘要:铁路客货运业务诞生已有近一个世纪了,作为现有交通工具最为普遍的一种,铁路客货运给民众的生活、出行带来了极大的方便。
铁路客货运业务中,售票是必不可少的一个环节。
自铁路运营以来,售票方式在“大提速”似的的在发展,早期的车票还是纯手工制作,且售票结构单一,每个工作人员只能完成一种工作,若要买一张票需要2-3分钟的时间。
随着科技的发展,计算机的诞生,信息技术在管理上越来越深入而广泛的应用,管理系统的实施在技术上已逐步成熟。
任何单位若想把内部活动有机的组织起来,就需要建立与自身特点适应的管理系统。
本系统是根据售票人员的需求,同时方便购票人员,改变以前购票费时的难题,开发的一套车站票务管理系统。
本系统是在Linux环境下利用C语言基于MiniGUI图形界面开发的,数据库采用的是SQLite3。
通过对数据库SQLite3的增、删、改、查等操作实现系统订票,退票,改签票务以及管理员对数据及时更新等功能,实现方便购票人员和工作人员,以达到即可提高工作人员工作效率,又节省购票人员时间的目的。
关键词:车站票务管理系统,Linux,MiniGUI,SQLite3目录毕业设计(论文)任务书I摘要IIABSTRACT III第1章绪论11.1 论文研究主要内容11.2 国内外现状21.3 论文组织结构2第2章关键技术介绍 42.1关键性开发技术的介绍42.1.1Linux环境下C编程42.1.2MiniGUI图形开发界面52.1.3SQLite数据库操作5第3章系统分析73.1体系结构73.1.1功能描述73.1.2业务模型73.2系统开发环境93.3系统任务的可行性分析93.3.1技术可行性93.3.2经济可行性9第4章系统设计114.1设计指导思想和原则114.1.1指导思想114.1.2软件设计原则114.2构架概述134.3系统的概要设计144.3.1系统结构模块与程序的关系144.3.2运行模式154.3.3数据结构164.3.4功能模块设计164.3.5系统故障处理设计16第5章系统实现185.1开发环境185.2功能说明185.3功能实现185.3.1MiniGUI图形界面185.3.2查票模块205.3.3订票模块215.3.4退票模块215.3.5改票模块22第6章系统测试236.1测试方案及测试用例236.1.1订票模块236.1.2退票模块236.1.3查票模块236.1.4改票模块23第7章结论24参考文献25致谢26功能说明车站票务管理系统的核心部分为四个模块,即订票、退票、查票、改票四个模块,实现此四个模块的主要技术就是对SQLite3数据库的增、删、改、查。
列车时刻管理系统C语言程序设计(源代码)
一、问题分析随着社会的不断发展,人们在交通方式的选择上有了不同以往的选择,以前的靠人力,畜力,以及摩托车,现在人们的选择更多的会放在了汽车,飞机还有列车上。
每当春节前后时,都有一批民工潮,学生潮,这些农民工和学生都来自于祖国的各个地方,因此车站如何合理有序的安排列车出站到站时间成了一个很关键的内容,有助于维持车站的秩序以及减少不必要的等待。
而本课题的列车时刻管理系统也应用与这些地方,不过由于专业知识学的还不多,因此还不能将一个完整的列车时刻管理系统完全的展示出来,只是在最基础的层面上做了一些工作。
二、系统功能设计1.添加新记录:利用结构数组的方式来添加新记录,并且保存在文件train.txt文件中,并且记录上限为300,新纪录的内容包括:出站地址,出站的时刻(时),出站时刻(分),到站地址,到站时刻(时),到站时刻(分)。
2.查看:查询功能总共分为四种方式:①按出站地址查询②按出站时刻查询③按到站地址查询④按到站时刻查询,这个功能由于能力有限,只限查找单一数据。
3.修改:修改功能:根据出站的地址,查找出对应的一组数据的内容,然后逐一修改。
4.删除:修改功能总共分为两个部分:①单一删除(按照出站地址)②全部删除5.保存:每执行一个任务后程序会自动将数据写入train.txt文档中.三、模块(函数)划分void main():主函数void MainMenu():主菜单列表void ShowMenu():查询菜单列表void AddNew():添加新的数据int IsLoop():循环输入数据void Display():输出所有的函数void Search_ccity():按出站地址查询void Search_dcity():按到站地址查询void Search_ctime():按出站时刻查询void Search_dtime():按到站时刻查询void ChkData(char city1[],char city2[],int hour1,int minute1,int hour2,int minute2):数据检测void Record_Modify():修改数据void DeleteMenu():删除菜单列表void DeleteOne():删除一组数据void DeleteAll():删除所有数据void ReadFromFile():从文件中读入void WriteToFile():从文件中写入四、模块的算法设计(部分主要函数的代码)1.整体构造:2.结构体:struct Record{int hour1;int hour2;int minute1;int minute2;char city1[20];char city2[20];};3.主菜单:void MainMenu(){system("cls");printf(”---—-—-———---—-—--———-——主菜单-—--——-——————-—--———----———-—\n");int option;printf(”—-—-—-—--——-————-——--1—添加新记录----—--—————-—-————-——-——-\n");printf(”--————-——--—-——-———-—2—查看——---—--—-——--—-——-———-———-—————\n”);printf(”-—--——----—-—-——--—-—3-修改—-—--—-—-—-——————-——----———-———-\n”);printf("-————-—-—-—---—--—-—-4—删除——--———-———-———-----————----————\n");printf("—-—---—-—-———-—--————5-退出程序——---—-—-—--—-—--—----————--\n”);printf("请选择:\n”);scanf("%d",&option);getchar();switch (option){case 1:AddNew();break;case 2:ShowMenu();break;case 3:Record_Modify();break;case 4:DeleteMenu();break;case 5:exit(0);}}4.数据检测:void ChkData(char city1[],char city2[],int hour1,int minute1,int hour2,int minute2){if (strlen(city1)>20){printf(”出站地址的字符不能超过20个!\n”);MainMenu();}if (strlen(city2)〉20){printf("到站地址不能超过20位!\n");MainMenu();}if (hour1〈0||hour1〉23){printf("时刻输入错误(0〈=hour<24)!\n”);MainMenu();}if (hour2〈0||hour2〉24){printf(”时刻输入错误(0<=hour<24)!\n”);MainMenu();}if (minute1〈0||minute1〉59){printf(”时刻输入错误(0〈=minute〈59)!\n");MainMenu();}if (minute2〈0||minute2〉59){printf(”时刻输入错误(0<=minute〈59)!\n");MainMenu();}}5.读入文件中的数据:void ReadFromFile(){FILE *fp;int i;if ((fp=fopen(”train。
火车票订票系统代码C
break;Βιβλιοθήκη }}if (p==NULL)
cout<<"未找到!"<<endl;
}
void Busman::ExitTicket()
{
string s,t;
node *p;
cout<<"退票的班次是:";
cin>>s;
"<<endl;
for (p=Busman::BusHead; p!=NULL; p=p->Next)
{
if ((sel==1 && p->Num==s) || (sel==2 && p->EndPlace==s))
{
cout<<p->Num<<"\t"<<p->SetoutTime<<"\t"<<
if (time >= p->SetoutTime) cout<<"(已发车)"<<endl;
else cout<<"(未发车)"<<endl;
一个简单的火车票售票管理系统
1 / 18()#include<stdio.h> #include<malloc.h> #define MAX 100 #define N 50typedef struct time //时间类型{int x,y,z;//分别对应年,月,日}TIME;int id;//购票人证件号TIME date;//购票日期}CNODE;typedef struct tnode //车次信息类型{char data;//车次编号struct tnode *lchild,*rchild; CNODE *head; }TNODE;void create();//按车次建立二叉排序树void insert(int );//增加新的车次(二叉排序树的插入)void del();//取消车次(二叉排序树节点删除)void inorder(TNODE *);//中序遍历车次二叉排序树(仅显示车次信息)voidinorder_all(TNODE *);//中序遍历车次二叉排序树(显示车次及售票信息)voidpreorder(TNODE *);//先序遍历车次二叉排序树(仅显示车次信息)TNODE*search();//按车次编号搜索CNODE *insert_c(CNODE *);//插入新的售票信息(单张)2 / 18CNODE *insert_c_more(CNODE *);//插入新的售票信息(批量)CNODE *del_c(CNODE *,CNODE *);//退票处理(删除售票信息)CNODE *search_c(CNODE *,int);//按票号查询void search_c_id(CNODE *,int);//按购票人证件号搜索(限定某车次)void search_c_id_all(TNODE *,int);//按购票人证件号搜索(所有车次)void search_date(CNODE *,TIME);//按购票日期搜索(限定某车次)void search_date_all(TNODE *,TIME);//按购票日期搜索(所有车次)void print_c(CNODE *);//输出售票纪录(单张)void print_c_all(CNODE *);//输出售票纪录(批量)TNODE *root=NULL; void main(){int i,func,no,ok; TNODE *t; CNODE *c; TIME d; printf(\n\n\n);for(i=0;i<15;i++) printf(=); printf(列车售票信息管理系统);for(i=0;i<15;i++) printf(=); printf(\n); printf(\t1.车次信息管理\n); printf(\t2.售票记录管理\n);3 / 18printf(\t3.售票记录查询\n); printf(\t4.售票记录一览\n); printf(\t5.退出系统\n);for(i=0;i<N;i++) printf(=); printf(\n请选择您所需要的功能: ); fflush(stdin); scanf(%d,&func); switch(func){ case 1:printf(\n\n车次信息管理>>>>\n); for(i=0;i<N;i++) printf(=);printf(\n\t 1.增加新的车次); printf(\n\t 2.取消车次); printf(\n\t 3.返回上级菜单\n);4 / 18for(i=0;i<N;i++) printf(=); printf(\n请选择您所需要的功能: ); fflush(stdin); scanf(%d,&func); switch(func){ case 1: create(); printf(\n售票信息更新成功!\n\n); break;case 2:del();break; case 3:main();break; default:printf(\n[错误]功能号输入有误!请重新输入!);}break; case 2: printf(\n\n售票记录管理>>>>\n); for(i=0;i<N;i++) printf(=);printf(\n\t1.增加新的售票记录); printf(\n\t2.退票);5 / 18printf(\n\t3.返回上级菜单\n); for(i=0;i<N;i++) printf(=); printf(\n请选择您所需要的功能: );fflush(stdin); scanf(%d,&func); switch(func){ case 1: t=search();if(t!=NULL) t->head=insert_c_more(t->head); break; case 2:t=search();printf(需要退票的票号: );scanf(%d,&no);t->head=del_c(t->head,search_c(t->head,no)); break;case 3:main();break; default:6 / 18printf(\n[错误]功能号输入有误!请重新输入!);}break; case 3:printf(\n\n售票记录查询>>>>\n); for(i=0;i<N;i++) printf(=);printf(\n\t 1.按票号搜索); printf(\n\t2.按购票者证件号搜索); printf(\n\t3.按购票日期搜索); printf(\n\t4.返回上级菜单\n); for(i=0;i<N;i++) printf(=); printf(\n请选择您所需要的功能: );fflush(stdin); scanf(%d,&func); switch(func){ case 1: t=search();if(t!=NULL){7 / 18printf(\n请输入您所要查询的票号: );scanf(%d,&no); c=search_c(t->head,no);if(c==NULL)printf([错误]没有该票号的纪录!该票还未售出或为废票!自动返回上级菜单\n...);}break; case 2:printf(\n请输入您所要查询的购票者证件号: );scanf(%d,&no); search_c_id_all(root,no);printf(搜索完毕!自动返回上级菜单\n...); break; case 3: do{ printf(\n请输入您所要查询的日期(格式: yy-mm-dd): );scanf(%d-%d-%d,&d.x,&d.y,&d.z); if(d.y<13&&d.y>0){8 / 18if(d.y==1||d.y==3||d.y==5||d.y==7||d.y==8||d.y==10||d.y==12)if( d.z<32&&d.z>0) ok=1;else if(d.z==2)if(d.z<30&&d.z>0) ok=1; elseif(d.z<31&&d.z>0) ok=1;}else ok=0;if(!ok) printf(\n[错误]日期输入有误!请重新输入!); }while(!ok); printf(\n指定车次吗?(1->是,0->否): );scanf(%d,&ok);if(ok) search_date(search()->head,d); else search_date_all(root,d); break;case 4:main();break; default:printf(\n[错误]功能号输入有误!自动返回上级菜单\n...);}break;case 4: printf(\n\n售票记录一览>>>>\n);for(i=0;i<N;i++) printf(=); printf(\n\t 1.仅浏览车次); printf(\n\t9 / 182.指定车次已售票记录); printf(\n\t3.所有车次已售票记录); printf(\n\t4.测试:先序遍历车次); printf(\n\t5.返回上级菜单\n); for(i=0;i<N;i++) printf(=); printf(\n请选择您所需要的功能: );fflush(stdin); scanf(%d,&func); switch(func){ case 1:printf(\n+++仅浏览车次\n);if(root==NULL) printf([错误]无车次纪录!);else{inorder(root);printf(\n);} break; case 2:printf(\n+++指定车次已售票记录\n);10 / 18t=search(); if(t!=NULL){ print_c_all(t->head); printf(\n);}break; case 3:printf(\n+++所有车次已售票记录\n); if(root==NULL) printf([错误]无车次纪录!); else{inorder_all(root);printf(\n);} break; case 4: printf(\n+++测试:先序遍历车次\n);if(root==NULL) printf([错误]无车次纪录!);else{preorder(root);printf(\n);} break;case 5:main();break; default:printf(\n[错误]功能号输入有误!自动返回上级菜单\n...);}break;case 5:exit (0); default:printf(\n[错误]功能号输入有误!请重新输入!);}main();}void11 / 18inorder_all(TNODE *ptr){if(ptr!=NULL){inorder_all(ptr->lchild); printf(%d: \n,ptr->data); print_c_all(ptr->head); printf(\n); inorder_all(ptr->rchild);}}void inorder(TNODE *ptr){if(ptr!=NULL){inorder(ptr->lchild);printf(%d\t,ptr->data); inorder(ptr->rchild);}}void preorder(TNODE*ptr){if(ptr!=NULL){printf(%d\t ,ptr->data);preorder(ptr->lchild);preorder(ptr->rchild);}} void print_c(CNODE *tkt){ if(tkt!=NULL) printf(\t%d\t%d\t%d-%d-%d\n,tkt->no,tkt->id,tkt->date.x,tkt->date. y,tkt->date.z);}void print_c_all(CNODE *head){int i=0,j=0;if(head==NULL){printf(\n记录为空!\n);return;} for(i=0;i<N;i++) printf(=);printf(\nNO\t票号\t购票者证件号\t购票日期(年-月-日)\n);for(i=0;i<N;i++) printf(-); for(j=0;head!=NULL;j++){12 / 18printf(\n%d,j); print_c(head);head=head->next;}printf(\n); for(i=0;i<N;i++) printf(-); printf(\n总计%d条记录\n,j); for(i=0;i<N;i++) printf(=); printf(\n);}void create(){int n,i; int k[MAX];printf(\n您所希望增加车次的数量: );scanf(%d,&n); for(i=0;i<n;i++){printf(新增第%d列车次: ,i+1);scanf(%d,&k[i]);}for(i=0;i<n;i++)insert(k[i]);}void insert(int m){TNODE *p1,*p2;if(root==NULL){root=(TNODE *)malloc(sizeof(TNODE));root->data=m;root->lchild=root->rchild=NULL; root->head=NULL;}else {p1=root; while(m!=p1->data){if((m<p1->data)&&(p1->lchild!=NULL))p1=p1->lchild;else if((m>p1->data)&&(p1->rchild!=NULL))p1=p1->rchild;13 / 18else if((m<p1->data)&&(p1->lchild==NULL)){p2=(TNODE*)malloc(sizeof(TNODE)); p2->data=m;p2->lchild=p2->rchild=NULL; p2->head=NULL; p1->lchild=p2; return;}else if((m>p1->data)&&(p1->rchild==NULL)){p2=(TNODE *)malloc(sizeof(TNODE)); p2->data=m;p2->lchild=p2->rchild=NULL; p2->head=NULL; p1->rchild=p2; return;}}printf(\n[错误]未能成功增加车次%d,车次号%d已存在!,m,m);}}TNODE *search(){int key; TNODE *p; p=root;printf(\n输入您所要查找的车次编号: );scanf(%d,&key);while(p!=NULL&&p->data!=key){14 / 18if(key<p->data){p=p->lchild;}else if(key>p->data){p=p->rchild;}}if(p==NULL) printf(\n该车次不存在!);return(p);}void del(){int key;TNODE *p1,*p2,*p3,*temp; p1=p2=root; p3=temp=NULL;printf(\n请输入您想要取消的车次编号:);scanf(%d,&key);while(p2!=NULL&&p2->data!=key){ if(key<p2->data){p1=p2;p2=p2-> lchild;}elseif(key>p2->data){p1=p2;p2=p1->rchild;}}if(p2==NULL){printf(\n[错误]该车次不存在!返回上级菜单\n...);return;}else if(p2->lchild==NULL&&p2->rchild==NULL){if(p1->lchild==p2)p1->lchild=NULL;if(p1->rchild==p2) p1->rchild=NULL; temp=p2;if(root==p2){temp=root;root=NULL;}}else{ if(p2->rchild==NULL){ temp=p2->lchil d; p2->data=temp->data;15 / 18p2->lchild=temp->lchild;p2->rchild=temp->rchild;}elseif(p2->lchild==NULL){ temp=p2->rchild; p2->data=temp->data;p2->lchild=temp->lchild; p2->rchild=temp->rchild;}else{ p3=p2; temp=p2->lchild;while(temp->rchild!=NULL){p3=temp;temp=temp->rchild;}p2->data=temp->data;if(p3==p2) p3->lchild=temp->lchild; else p3->rchild=temp->lchild;}}free(temp);printf(车次%d已取消!\n\n,key);}CNODE *insert_c(CNODE*head){CNODE *k,*p;k=(CNODE *)malloc(sizeof(CNODE)); do{printf(\n车票编号: );scanf(%d,&k->no); p=search_c(head,k->no);if(p!=NULL) printf(\n[错误]该票已被购买!请重新选择!\n);16 / 18}while(p!=NULL); printf(购票者证件号: );scanf(%d,&k->id); printf(购票日期(格式: yy-mm-dd): );scanf(%d-%d-%d,&k->date.x,&k->date.y,&k->date.z); k->next=head; head=k;return(head);}CNODE *insert_c_more(CNODE *head){ int n,i; printf(\n请输入批量新增售票记录数: );fflush(stdin); scanf(%d,&n);for(i=0;i<n;i++) head=insert_c(head); printf(\n售票记录更新成功!\n);return(head);}CNODE *search_c(CNODE *head,int id){ CNODE*temp,*s; s=temp=head;17 / 18while(temp!=NULL&&temp->id!=id){s=temp;temp=temp->next;} print_c(temp);if(temp!=NULL) return(s);else return NULL;}void search_c_id(CNODE *head,int id){ CNODE *s,*head_s; s=head_s=NULL;if(head==NULL) printf(无该证件号纪录!\n);while(head!=NULL){ if(head->id==id){s=(CNODE *)malloc(sizeof(CNODE));s->no=head->no;s->id=head->id;s->date=head->date;s->next=head_s;head_s=s;}head=head->next;}print_c_all(head_s);p rintf(\n);}void search_c_id_all(TNODE *ptr,int id){if(ptr!=NULL){search_c_id_all(ptr->lchild,id); printf(\n车次: %d\n,ptr->data); search_c_id(ptr->head,id); search_c_id_all(ptr->rchild,id);}} void search_date(CNODE *head,TIME t){ CNODE *s,*head_s;s=head_s=NULL;18 / 18while(head!=NULL){ if(t.x==head->date.x) if(t.y==head->date.y)if(t.z==head->date.z){s=(CNODE *)malloc(sizeof(CNODE));s->no=head->no;s->id=head->id;s->date=head->date;s->next=head_s;head_s=s;}head=head->next;}print_c_all(head_s);p rintf(\n);}void search_date_all(TNODE *ptr,TIME t){if(ptr!=NULL){search_date_all(ptr->lchild,t); printf(\n车次: %d\n,ptr->data);search_date(ptr->head,t); search_date_all(ptr->rchild,t);}} CNODE *del_c(CNODE *head,CNODE *p){ CNODE *temp;if(p==NULL) printf([错误]该票未售出或为废票!返回上级菜单\n...);else if(p==head){head=NULL;free(p);}else{temp=p->next; p->next=temp->next; free(temp);}return(head);}。
火车票售票系统c语言设计
火车票售票系统的设计可以使用C语言来实现。
下面是一个简单的示例,展示了如何设计一个基本的火车票售票系统:```c#include <stdio.h>#include <stdlib.h>#define MAX_SEATS 100typedef struct {int seat_number;char passenger_name[50];} Ticket;Ticket tickets[MAX_SEATS];int total_tickets = 0;void displayMenu() {printf("\n=== 火车票售票系统 ===\n");printf("1. 购买票\n");printf("2. 查询票\n");printf("3. 取消票\n");printf("4. 退出\n");printf("=====================\n");printf("请输入选项: ");}void buyTicket() {if (total_tickets >= MAX_SEATS) {printf("对不起,票已售完。
\n");return;}Ticket ticket;printf("请输入座位号: ");scanf("%d", &ticket.seat_number);// 检查座位号是否已经被购买for (int i = 0; i < total_tickets; i++) {if (tickets[i].seat_number == ticket.seat_number) {printf("对不起,该座位已被购买。
\n");return;}}printf("请输入乘客姓名: ");scanf("%s", ticket.passenger_name);tickets[total_tickets++] = ticket;printf("购票成功!\n");}void queryTicket() {int seat_number;printf("请输入座位号: ");scanf("%d", &seat_number);for (int i = 0; i < total_tickets; i++) {if (tickets[i].seat_number == seat_number) {printf("座位号: %d\n", tickets[i].seat_number);printf("乘客姓名: %s\n", tickets[i].passenger_name); return;}}printf("对不起,该座位未被购买。
火车票查询系统代码
火车票查询系统代码.txt41滴水能穿石,只因为它永远打击同一点。
42火柴如果躲避燃烧的痛苦,它的一生都将黯淡无光。
#include <iostream.h>#include <string.h>void welcome(); //欢迎系统void choose(); //选择系统void time(int year,int month,int day); //时间判断系统void booktickets(); //订票子系统void sealticket(); //售票子系统void sealticket(char begin[10],char end[10],int number);void returntickets(); //退票子系统int statisticstrain(char begin[10],char end[10]); //站站查询 |int statisticstrain1(char trainnum[10]); //车次查询 } 统计子系统int statisticstrain2(char station[10]); //车站查询 |void querytrain(); //查询子系统int generateddata(char begin[10],char end[10]); //站站查询 |int generateddata1(char trainnum[10]); //车次查询 } 生成数据子系统int generateddata2(char station[10]); //车站查询 |void quit(); //退出系统//欢迎系统void welcome(){cout<<"********************************************************"<<endl;cout<<"* 欢 * 迎 * 使 * 用 * 火 * 车 * 票 * 订 * 票 * 系 * 统 *"<<endl;cout<<"********************************************************"<<endl;cout<<"* 本订票系统有以下功能: *"<<endl;cout<<"* 1:订购火车票 *"<<endl;cout<<"* 2:预定火车票 *"<<endl;cout<<"* 3:退订火车票 *"<<endl;cout<<"* 4:查询车票信息 *"<<endl;cout<<"* 5:退出系统 *"<<endl;cout<<"********************************************************"<<endl;cout<<"请选择所要执行的功能: "<<endl;choose();}//选择系统void choose(){int i;cin>>i;switch (i)case 1:booktickets();break;case 2:sealticket();break;case 3:returntickets();break;case 4:querytrain();break;case 5:quit();break;default:cout<<"请在数字 1-5 之间重新您的输入选择!"<<endl; choose();break;}}//时间判断系统void time(int year,int month,int day){int jy = 1;int y = year % 4;if(month == 2){if(year % 4 == 0){if((year/100)%4 != 0){if(day > 29){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}else{if(day > 28){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}}else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){if(day > 31){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}else if(month == 4 || month == 6 || month == 9 || month == 12){if(day > 30){cout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}elsecout<<"请输入正确的日期格式!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;}}//订票子系统void booktickets(){char begin[10],end[10];int year,month,day;cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;cout<<"请输入您所要订购的票的出发日期!"<<endl;cout<<"请输入出发年份:"<<endl;cin>>year;cout<<"请输入出发月份:"<<endl;cin>>month;cout<<"请输入出发日期:"<<endl;cin>>day;time(year,month,day); //判断输入的时间是否正确cout<<"出发日期为:"<<year<<"-"<<month<<"-"<<day<<endl; int number;cout<<"请输入所要订购的火车票数量:"<<endl;cin>>number;sealticket(begin,end,number); //调用售票系统(2)}//售票子系统(1)void sealticket(){char begin[10],end[10];cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;int number;cout<<"请输入所要订购的火车票数量:"<<endl;cin>>number;int j = statisticstrain(begin,end); //调用站站统计子系统if(j == 1){char trainnum[10];cout<<"请选择火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;cout<<endl;cout<<"您所需要的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<'\t'<<"票价:"<<price<<endl;cout<<"出发日期为:2010-12-24"<<endl;cout<<"您一共订购了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"购买成功!"<<endl;cout<<"继续购买请输入 1 "<<'\t'<<"退出购票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)sealticket();elsewelcome();}elsewelcome();}else if(j == 0)welcome();}//售票子系统(2)void sealticket(char begin[10],char end[10],int number){int j = statisticstrain(begin,end); //调用站站统计子系统if(j == 1){char trainnum[10];cout<<"请选择火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;cout<<endl;cout<<"您所需要的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<'\t'<<"票价:"<<price<<endl;cout<<"您一共订购了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"购买成功!"<<endl;cout<<"继续购买请输入 1 "<<'\t'<<"退出购票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)sealticket();elsewelcome();}elsewelcome();}else if(j == 0)welcome();}//退票子系统void returntickets(){char begin[10],end[10];cout<<"请输入出发地:"<<endl;cin>>begin;cout<<"请输入目的地:"<<endl;cin>>end;char trainnum[10];cout<<"请输入火车车次:"<<endl;cin>>trainnum;int price;cout<<"请选择票价:"<<endl;cin>>price;int number;cout<<"请输入所要退订的火车票数量:"<<endl;cin>>number;cout<<endl;cout<<"您所要退订的火车票信息:"<<endl;cout<<"出发地:"<<begin<<'\t'<<"目的地"<<end<<'\t'<<"车次:"<<trainnum<<"票价:"<<price<<endl;cout<<"您一共退订了 "<<number<<" 张"<<endl;cout<<endl;cout<<"确认无误后请输入 1 "<<'\t'<<"取消请输入 0 "<<endl;int i;cin>>i;if(i == 1){cout<<endl;cout<<"退订成功!"<<endl;cout<<"继续退订请输入 1 "<<'\t'<<"退出退票系统请输入 0 "<<endl;cin>>end;int j;cin>>j;if(j == 1)returntickets();elsewelcome();}elsewelcome();}//查询子系统void querytrain(){int i;cout<<endl;cout<<"请选择您要的查询方式:"<<endl;cout<<"1、(出发)站(到达)站查询"<<endl;cout<<"2、车次查询"<<endl;cout<<"3、车站查询"<<endl;cout<<endl;cin>>i;if(i == 1){char from[10],to[10];cout<<"请输入出发站:"<<endl;cin>>from;cout<<"请输入到达站:"<<endl;cin>>to;cout<<endl;statisticstrain(from,to);cout<<endl;welcome();}else if(i == 2){char trainnum[10];cout<<"请输入车次:"<<endl;cin>>trainnum;cout<<endl;statisticstrain1(trainnum);welcome();}else if(i == 3){char station[10];cout<<"请输入车站:"<<endl;cin>>station;cout<<endl;statisticstrain2(station);welcome();}}//统计子系统——站站查询int statisticstrain(char begin[10],char end[10]) {int i = generateddata(begin,end);cout<<endl;return i;}//生成数据子系统——站站int generateddata(char begin[10],char end[10]){if(!strcmp(begin,"changzhou") && !strcmp(end,"nanjing")){cout<<endl;cout<<"从"<<begin<<"到"<<end<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有从 "<<begin<<" 到 "<<end<<" 的火车!"<<endl;return 0;}}//统计子系统——车次查询int statisticstrain1(char trainnum[10]){int i = generateddata1(trainnum);cout<<endl;return i;}//生成数据子系统——车次int generateddata1(char trainnum[10]){if(!strcmp(trainnum,"k8372")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;return 1;}else if(!strcmp(trainnum,"2582")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;return 1;}else if(!strcmp(trainnum,"g7124")){cout<<endl;cout<<"车次为"<<trainnum<<"的火车有:"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有车次为 "<<trainnum<<trainnum[0]<<" 的火车!"<<endl;return 0;}}//统计子系统——车站查询int statisticstrain2(char station[10]){int i = generateddata2(station);cout<<endl;return i;}//生成数据子系统——车站int generateddata2(char station[10]){if(!strcmp(station,"changzhou") || !strcmp(station,"nanjing")){cout<<endl;cout<<"出发站(经过站)为"<<station<<"的火车有:"<<endl;cout<<endl;cout<<"车次:k8372"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:41"<<'\t'<<"到达时间:02:17"<<'\t'<<"参考价格(元): 硬座:22 软座:34 硬卧(上/中/下):68/73/76 软卧(上/下):103/109"<<endl;cout<<endl;cout<<"车次:2582"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:00:54"<<'\t'<<"到达时间:02:24"<<'\t'<<"参考价格(元): 硬座:19 软座:31 硬卧(上/中/下):65/70/73 软卧(上/下):100/106"<<endl;cout<<endl;cout<<"车次:g7124"<<'\t'<<"发站:(过)常州"<<'\t'<<"到站:(过)南京"<<'\t'<<"发车时间:07:56"<<'\t'<<"到达时间:08:39"<<'\t'<<"参考价格(元): 一等软座:105"<<endl; return 1;}else{cout<<endl;cout<<"没有经过 "<<station<<" 的火车!"<<endl;return 0;}}//退出系统void quit(){cout<<endl;cout<<"感谢您的使用!"<<endl;}void main(){welcome();}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 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",\ "#","#","#","#"