订票代码
- 格式:doc
- 大小:119.50 KB
- 文档页数:9
火车订票系统源码(一)#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。
Airline.h#pragma once#include<string>using std::string;#include<iostream>using std::istream;using std::ostream;#include<string>using std::endl;using std::cout;using std::cin;#include"DataStructure.h"#include"Passenger.h"class AirLine;ostream &operator<<(ostream &output ,const AirLine& line);class AirLine{friend void InitAirLine(AirLine *line);friend ostream &operator<<(ostream &output,const AirLine& line); public:AirLine(void);~AirLine(void);string GetEndPoint();int GetSeatNum(int);int GetSeatRemain(int);void SetSeatRemain(int num,int whickWeek);string GetFlightNum(void);void InsertPassenger(Passenger& temp);bool IsFly(int whichWeek) const;void InsertAwait(Passenger& temp);bool DeletePassenger(Passenger&);int IfAwaitBook(int tiNum, int whichWeek);private:string endPoint;string flightNum;string airNum;bool week[8];int seatNum[8];int seatRemain[8];MyList<Passenger> pList;MyQueue<Passenger> pQueue;};Airline.cpp#include"AirLine.h"AirLine::AirLine(void){for(int i=0;i<8;i++)week[i]=false;}AirLine::~AirLine(void){}string AirLine::GetEndPoint(){return endPoint;}ostream &operator<<(ostream &output,const AirLine &line){output<<"终点站: "<<line.endPoint<<"\n\n"<<"航班号: "<<line.flightNum<<"\n\n"<<"飞机号: "<<line.airNum<<"\n\n"<<"剩余票数:\n";for(int i=1;i<8;i++)if(line.IsFly(i))output<<"周"<<i<<" "<<line.seatRemain[i]<<endl;string weekName[8]={" ","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sund ay"};output<<"飞行日:";for(int i=1;i<8;i++)if(line.week[i])output<<weekName[i]<<"\t";cout<<endl;return output;}int AirLine::GetSeatNum(int whichWeek){return seatNum[whichWeek];}int AirLine::GetSeatRemain(int whichWeek){return seatRemain[whichWeek];}void AirLine::SetSeatRemain(int num,int whichWeek) {seatRemain[whichWeek]-=num;}string AirLine::GetFlightNum(void){return flightNum;}void AirLine::InsertPassenger(Passenger& temp) {pList.InsertNode(temp);}bool AirLine::IsFly(int whichWeek) const{return week[whichWeek];}void AirLine::InsertAwait(Passenger& temp){pQueue.EnQueue(temp);}bool AirLine::DeletePassenger(Passenger& temp) {seatRemain[temp.GetWeek()]+=temp.GetTickets();return pList.DeleteNode(temp);}int AirLine::IfAwaitBook(int tiNum, int whichWeek) {if(pQueue.Empty())return 0;Passenger node,tnode;MyQueue<Passenger> tempQueue;while(!pQueue.Empty()){pQueue.DnQueue(node);if(node.GetTickets()<tiNum&&node.GetWeek()==whichWeek) break;tempQueue.EnQueue(node);}while(!tempQueue.Empty()){tempQueue.DnQueue(tnode);pQueue.EnQueue(tnode);}if(node.GetTickets()<tiNum&&node.GetWeek()==whichWeek) return node.GetTickets();elsereturn 0;}Passenger.h#pragma once#include<string>using std::string;enum TicketGrade{AA,BB,CC};class Passenger{public:~Passenger(void);Passenger(const string &passengerName=" ",int tick=0,int g=1,int w=1);bool operator==(Passenger & d);int GetTickets();int GetWeek();private:string name;int tickets;TicketGrade grade;int flightWeek;};Passenger.cpp#include"Passenger.h"Passenger::~Passenger(void){}Passenger::Passenger(const string &passengerName,int tick,int g,int w) {name=passengerName;tickets=tick;switch(g){case 1:grade=AA;break;case 2:grade=BB;break;case 3:grade=CC;break;default:break;}flightWeek=w;}bool Passenger::operator==(Passenger & d){if(d.tickets!=tickets)return false;if(!=name)return false;if(d.flightWeek!=flightWeek)return false;if(d.grade!=grade)return false;return true;//TODO: insert return statement here }int Passenger::GetTickets(){return tickets;}int Passenger::GetWeek(){return flightWeek;}DataStructure.h#include<cstdlib>//LQNode classtemplate<typename T>class MyList;template<typename T>class MyQueue;template<typename T>class LQNode{friend class MyList<T>;friend class MyQueue<T>;public:LQNode();LQNode(T);~LQNode();private:T data;LQNode<T> *next;};template<typename T> LQNode<T>::LQNode(){//data=T(0);next=NULL;}template<typename T> LQNode<T>::LQNode(T node) {data=node;next=NULL;}template<typename T> LQNode<T>::~LQNode(){}//MyList classtemplate<typename LT> class MyList{public:MyList();~MyList();void InsertNode(LT &);bool DeleteNode(LT &);private:LQNode<LT> *head;};template<typename LT> MyList<LT>::MyList(){head=new LQNode<LT>;head->next=NULL;}template<typename LT>MyList<LT>::~MyList(){}template<typename LT>void MyList<LT>::InsertNode(LT &temp){LQNode<LT> *node=new LQNode<LT>(temp);node->next=head->next;head->next=node;}template<typename LT>bool MyList<LT>::DeleteNode(LT &temp){LQNode<LT> *p,*q;p=head->next;q=head;while(p!=NULL){if(p->data==temp){q->next=p->next;free(p);return true;}q=p;p=p->next;}return false;}//MyQueue classtemplate<typename QT>class MyQueuepublic:MyQueue();~MyQueue();void EnQueue(QT &);void DnQueue(QT &);bool Empty();private:LQNode<QT> *front;LQNode<QT> *rear;};template<typename QT>MyQueue<QT>::MyQueue(){front=rear=new LQNode<QT>;}template<typename QT>MyQueue<QT>::~MyQueue(){}template<typename QT>void MyQueue<QT>::EnQueue(QT &temp){LQNode<QT> *node=new LQNode<QT>(temp);rear->next=node;node->next=NULL;rear=rear->next;}template<typename QT>void MyQueue<QT>::DnQueue(QT &temp){if(Empty())cout<<"对空"<<endl;elsetemp=front->next->data;return;}template<typename QT>bool MyQueue<QT>::Empty()return front->next==NULL;}Main.cpp#include"AirLine.h"#include<iostream>using std::cout;using std::cin;using std::endl;#include<iomanip>using std::setw;using std::setfill;void InitAirLine(AirLine *line);void InquireAirLine(AirLine* line);void BookTicket(AirLine *line);void ReturnTicket(AirLine *line);void IfAwait(AirLine &line,int tiNum,int whichWeek);void TransactBookTicket(AirLine &line,int tiNum,int whichWeek);void IfBookTicket(AirLine *line,string fiNum,int tiNum,int whichWeek); bool IsQuit();const int size=7;const int maxSeatNum=120;int main(){AirLine line[size];int select;InitAirLine(line);bool flag=false;while(!flag){cout<<"-------------------------------------------------------------------"<<endl;cout<<" 航空客运订票系统"<<endl;cout<<" 1 查询航线"<<endl<<" 2 订票业务"<<endl<<" 3 退票业务"<<endl;cout<<"-------------------------------------------------------------------"<<endl;cin>>select;while(cin.fail()||select<1||select>3){cout<<"输入错误,重新输入"<<endl;cin.clear();cin.ignore();cin>>select;}switch(select){case 1:InquireAirLine(line);break;case 2:BookTicket(line);break;case 3:ReturnTicket(line);break;default:cout<<"error";break;}system("pause");flag=IsQuit();system("cls");}return 0;}bool IsQuit(){char change;cout<<"是否退出该系统Y/y是N/n否"<<endl;while(true){cin>>change;switch(change){case'Y':case'y':return true;break;case'n':case'N':return false;break;default:cout<<"输入错误,重新输入"<<endl;break;}}return true;}void InquireAirLine(AirLine *line){string inquirePoint;cout<<"输入终点名:"<<endl;cin>>inquirePoint;for(int i=0;i<size;i++)if(line[i].GetEndPoint()==inquirePoint){cout<<line[i];return;}cout<<"对不起,没有到达该地的航班"<<endl; }void BookTicket(AirLine *line){int tiNum;int whichWeek;string fiNum;cout<<"输入航班号:"<<endl;cin>>fiNum;for(int i=0;i<size;i++)if(line[i].GetFlightNum()==fiNum){cout<<line[i];cout<<"输入订票额:"<<endl;cin>>tiNum;while(cin.fail()){cout<<"输入错误,重新输入"<<endl;cin.clear();cin.ignore();cin>>tiNum;}if(tiNum>maxSeatNum){cout<<"对不起,本公司暂时没有这么大的客机,请分开订票"<<endl;return;}cout<<"输入订票时间:"<<endl;cout<<"1星期一、星期二..."<<endl;cin>>whichWeek;while(cin.fail()||whichWeek>8||whichWeek<1||!line[i].IsFly(whichW eek)){cout<<"输入错误,重新输入"<<endl;cin.clear();cin.ignore();cin>>whichWeek;}if(tiNum>line[i].GetSeatRemain(whichWeek))IfAwait(line[i],tiNum,whichWeek);elseTransactBookTicket(line[i],tiNum,whichWeek);return;}cout<<"对不起,没有到达该地的航班"<<endl;}void ReturnTicket(AirLine *line){cout<<"为您办理退票业务:"<<endl;string fiNum;int whichWeek;int tiNum;int i;string name;cout<<"输入名字"<<endl;cin>>name;cout<<"输入航班号:"<<endl;cin>>fiNum;for(i=0;i<size;i++)if(line[i].GetFlightNum()==fiNum)break;if(i==size){cout<<"无此航班,请核对后输入"<<endl;return;}cout<<"输入订票时间:"<<endl;cout<<"1星期一、星期二..."<<endl;cin>>whichWeek;while(cin.fail()||whichWeek>8||whichWeek<1||!line[i].IsFly(whichW eek)){cout<<"输入错误,重新输入"<<endl;cin.clear();cin.ignore();cin>>whichWeek;}cout<<"输入订票额:"<<endl;cin>>tiNum;while(cin.fail()){cout<<"输入错误,重新输入"<<endl;cin.clear();cin.ignore();cin>>tiNum;}Passenger temp(name,tiNum,1,whichWeek);if(line[i].DeletePassenger(temp)==true){cout<<"办理退票完毕,谢谢合作"<<endl;IfBookTicket(line,fiNum,tiNum,whichWeek);}elsecout<<"您没有订票或输入信息错误,请核实后办理"<<endl; }void IfAwait(AirLine &line,int tiNum,int whichWeek){cout<<"空座不够,是否排队候补?Y/y是N/n否"<<endl;char change;bool flags=true;while(flags){cin>>change;switch(change){case'Y':case'y':{flags=false;Passenger temp(" ",tiNum,1,whichWeek);line.InsertAwait(temp);cout<<"已为您登记排队候补,请耐心等候"<<endl;}break;case'n':case'N':flags=false;cout<<"谢谢合作,再见。
|#include<> um,s[i].start,s[i].over,s[i].time,s[i].count 加航班信息\n""\t2.浏览航班信息\n""\t\t3.查找航班信息(按航班号)\t\t╮(╯_╰)╭\n"*"\t\t\t4.航班排序(按航班号)\n""\t\t\t\t5.订票业务\n""\to(︶︿︶)o\t\t\t6.退票业务\n""\t\t\t\t\t\t0.退出\n");printf("=================================================================== ============= ");"printf("请在0-6中选择以回车键结束: ");scanf("%d",&j);switch(j){case 1: add(); um); tart); ver); ime);ount); um); tart); ver); ime); ount); um==n)ount==0)ount!=0&&s[i].count>=n) ount=s[i].count-n;)printf("订票成功! ");break;}else if(s[i].count<n)ount);printf("是否需要重新输入机票数请输入y或n以回车键结束: ");ount=s[i].count+n;《printf("退票成功! ");}printf("是否继续请键入y或n以回车键结束: "); 航班号从小到大排序\n""\t2.按航班号从大到小排序\n");printf("******************************************************************* ************* ");!printf("请在1-2中选择以回车键结束: ");scanf("%d",&n); um>s[j].num)k=j;if(i!=k){.t=s[k];s[k]=s[i];s[i]=t;}}|}void paixu2() um<s[j].num)k=j;if(i!=k)*{t=s[k];s[k]=s[i];s[i]=t;}~}}。
飞机订票系统源代码#include<stdio.h> //标准输入、输出头文件#include<string.h> //包含字符串函数处理头文件#include<stdlib.h> //包含动态存储与释放函数头文件#define N 10000struct air //定义结构体数组{int num;char start[20];char over[20];char time[10];int count;}s[N];int i;int m=0;#define PRINT "%-d%12s%12s%10s%12d",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count // 定义输出格式void input(); //输入航班信息void print(); //输出航班信息void save(); //保存航班信息void read(); //读取航班信息void search(); //查找航班信息void shanchu(); //删除航班信息void dingpiao(); //订票信息void tuipiao(); //退票信息void xiugai(); //修改信息void main(){int j; printf(" ?---您好,欢迎进入中国民航治理系统~---? \n");printf("============================================================ ==================== \n");{printf(" -------- ? 1.输入航班信息 ?-------- \n"" -------- ? 2.浏览航班信息 ?-------- \n"" -------- ? 3.修改航班信息 ?-------- \n"" -------- ? 4.查找航班信息 ?-------- \n"" -------- ? 5.删除航班信息 ?-------- \n"" -------- ? 6.订票信息 ?-------- \n"" -------- ? 7.退票信息 ?--------\n "" -------- ? 0.退出 ?--------\n ");printf("============================================================ ===================\n ");printf("请在0-7中选择以回车键结束: ");scanf("%d",&j);switch(j){case 1: input();//调用输入模块break;case 2:print();//调用打印模块break;case 3:xiugai();//调用修改模块break;case 4:search();//调用查找模块break;case 5:shanchu(); //调用删除模块break;case 6:dingpiao();//调用订票模块break;case 7:tuipiao();//调用退票模块break;case 0:;break;}}while(j!=0); //判定结束printf("谢谢使用,再见~ "); }//主函数结束void input()//打印模块程序{char f[]="2008china"; //设置密码int y;printf("请输入密码并以回车键结束: ");scanf("%s",f); //读取密码if(strcmp(f,"2008china")==0){printf("请依次输入航班信息(机票数位0结束输入): ""完成输入信息请键入w以回车键结束 "); //打印提示信息printf("-------------------------------------------------------------------------- ");for(i=0;i<N;i++){printf("请输入航班号: ");scanf("%d",&s[i].num); //读取航班号printf("请输入起始站: ");scanf("%s",s[i].start);//读取起始站printf("请输入终点站: ");scanf("%s",s[i].over);//读取终点站printf("请输入时间: ");scanf("%s",s[i].time);//读取时间printf("请输入机票数(机票数为0结束输入): ",m);scanf("%d",&s[i].count);//读取机票数m++;printf("第%d个信息已经输完是否继续?按任意键继续,按 0结束",m);scanf("%d",&y);if(y==0)printf("请输入密码!");}}elseprintf("输入密码错误!请检查您的密码是否正确!谢谢!再见! "); } void save()//保存模块程序{FILE *fp,*fp1;//定义文件指针if((fp=fopen("chen.dat","wb"))==NULL)//打开文件并判定是否出错{printf("创建文件失败! ");//打印出错提示getchar();return;}if((fp1=fopen("hao.dat","wb"))==NULL)//打开文件并判定是否出错{printf("创建文件失败! ");//打印出错提示getchar();return;}for(i=0;i<m;i++)if(fwrite(&s[i],sizeof(struct air),1,fp)==0)//向文件写入数据,并判定是否出错printf("向文件输入数据失败! ");fprintf(fp1,"%d",m);fclose(fp);//关闭文件fclose(fp1);//关闭文件}void read()//从文件读取信息模块{FILE *fp,*fp1;//定义文件指针if((fp=fopen("chen.dat","rb"))==NULL)//打开文件,并判定是否出错if((fp1=fopen("hao.dat","rb"))==NULL)//打开文件并判定是否出错{printf("创建文件失败! ");//打印出错提示getchar();return;}fscanf(fp1,"%d",&m);fclose(fp1);//关闭文件for(i=0;i<m;i++)fclose(fp);//关闭文件}void print()//打印模块{char w[10];read();//调用读取文件函数printf("航班号起始站终点站时间机票数 ");for(i=0;i<m;i++){printf(PRINT);//打印信息}printf("请按任意键回车键结束返回上层菜单以: "); scanf("%s",w); }void search()//查询模块{char name1[20];char name2[20];char ii[10];int n,no;do{printf("请选择查找方式: ");//打印查询方式菜单printf("1.按航班号查找 ""2.按终点站查找 ""3.按航线查找 ""0.返回 ");printf("请在0-3中选择: ""按其他键以回车键结束返回主菜单: ");scanf("%d",&n);//读取查找方式if(n==0)break;switch(n){case 1:printf("请输入航班号: "); scanf("%d",&no);//航班号break;case 2:printf("请输入终点站名称: "); scanf("%s",name2);//读取终点站break;case 3:printf("请输入起始站名称: "); scanf("%s",name1);//读取起始站printf("请输入终点站名称: "); scanf("%s",name2);//终点站break;}read();//调用读取函数for(i=0;i<m;i++){if(strcmp(s[i].over,name1)==0||strcmp(s[i].over,name2)==0)//按终点站起始站判定输出条件{printf(" 查找航班信息成功! ");printf("航班号起始站终点站时间机票数 ");printf(PRINT);//打印信息break;}if(s[i].num==no)//按航班号判定输出条件{printf(" 查找航班信息成功! ");printf("航班号起始站终点站时间机票数 ");printf(PRINT);//打印信息break;}}no=0;//将航班号赋值为0printf("没有您需要的信息或查找完毕: ""是否继续查找?请键入yes或no以回车键结束 ");scanf("%s",ii); }while(strcmp(ii,"yes")==0);//判定结束 } void shanchu()//删除模块{char name1[20];char name2[20];char ii[10];char f[]="2008china";//设置密码int no,n;printf("请输入密码并以回车键结束: ");scanf("%s",f);//读取密码if(strcmp(f,"2008china")==0) //判定密码是否正确{do{printf("请选择删除以方式回车键结束: ");//打印删除方式菜单printf("*1.按航班号删除 ""*2.按航线删除 ""*0.返回 ");printf("请在0-2中选择以回车键结束: ");scanf("%d",&n);//读取删除方式if(n==0)break; //跳出循环switch(n){case 1:printf("请输入航班号: ");scanf("%d",&no);//读取航班号read();//调用读取函数break;//跳出循环case 2:printf("请输入起始站名称: ");scanf("%s",name1);//读取起始站printf("请输入终点站名称: ");scanf("%s",name2);//读取终点站read();//调用读取函数break;//跳出循环}for(i=0;i<m;i++){printf("查找完毕或没有这个信息 ");printf("是否继续删除 ");}printf("请键入yes或no以回车键结束 ");scanf("%s",ii); //读取是否继续信息save(); //调用读取函数if(!strcmp(ii,"yes")) //判定是否继续删除printf("请按任意键以回车键结束返回上层菜单: ");break;}while(n!=1&&n!=2&&n!=3&&n!=4&&n!=0); //判定结束}elseprintf("对不起密码错误!您不是治理员,不能使用此项功能!谢谢!再见! "); }void dingpiao()//订票模块{int n;char a[10];do{search();//调用查询模块printf("请输入您要订的机票数以回车键结束: "); scanf("%d",&n);//读取所订机票数if(n<0){printf("请输入有效的机票数~ ");//判定机票数是否出错break;}if(s[i].count!=0&&s[i].count>=n)//判定是否出错{s[i].count=s[i].count-n;save();//调用保存函数printf("订票成功! ");break;}if(s[i].count<n)//判定是否出错{printf("请输入有效的机票数: ");break;}printf("是否继续, 请输入yes或no以回车键结束: ");//判定是否继续订票scanf("%s",a);}while(!strcmp(a,"yes"));//判定结束} void tuipiao()//退票模块{int n;char a[10];do{search();//调用查询模块printf("请输入您要退的机票数目: ");scanf("%d",&n);//输入所退票数if(n<0) //判定票数是否有效printf("请输入有效的机票数~ ");s[i].count=s[i].count+n;save(); //调用保存模块printf("退票成功! ");printf("是否继续, 请键入yes或no以回车键结束: ");//判定是否继续退票scanf("%s",a);}while(!strcmp(a,"yes"));//判定并跳出循环 getchar();}void xiugai() //修改模块{struct xiu //定义结构体{int no;char name1[20];char name2[20];char time[20];int count;}x[1];char j[10];char f[]="2008china";//设置密码int n;printf("请输入密码并以回车键结束: "); scanf("%s",f);//读取密码if(strcmp(f,"2008china")==0)//判定是否出错{read();//调用读取模块do{printf( "请选择修改方式: ""*1,按航班号修改: ""*2,按航线修改: ");printf("请在1---2中修改以回车键结束: "); scanf("%d",&n);//读取修改方式switch(n){case 1:printf("请输入航班号: ");scanf("%d",&x[0].no);//读取航班号break;case 2:printf("请输入起始站: ");scanf("%s",x[0].name1);//读取起始站printf("请输入终点站: ");scanf("%s",x[0].name2);//读取终点站break;}for(i=0;i<m;i++){if(strcmp(s[i].over,x[0].name1)==0&&strcmp(s[i].over,x[0].name2)==0) //判定输出条件{printf("航班号起始站终点站时间机票数 ");printf(PRINT);break;}if(s[i].num==x[0].no)//判定输出条件{printf("航班号起始站终点站时间机票数 ");printf(PRINT);break;}}x[0].no=0; //将结构体中的号为零printf("请输入新航班号、起始站、终点站、时间(星期几)、机票数: ");scanf("%d%s%s%s%d",&x[0].no,x[0].name1,x[0].name2,x[0].time,&x[0].co unt);//定义输入格式s[i].num=x[0].no;//替换航班号strcpy(s[i].start,x[0].name1);//替换其始站strcpy(s[i].over,x[0].name2);//替换终点站strcpy(s[i].time,x[0].time);//替换时间s[i].count=x[0].count;//替换机票数save();//调用保存模块printf("是否继续,请键入yes或no以回车键结束: ");scanf("%s",j);}while(strcmp(j,"yes")==0); //判定结束}elseprintf("对不起密码错误!您不是治理员,不能使用此项功能!谢谢!再见! ");}。
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();}/*** 按车次搜索所有的车票信息*。
订票系统的源代码import java.util.*;import java.io.*;import ng.*;import java.text.*;import java.sql.*;import java.sql.Connection;class Stream{Scanner sc=new Scanner(System.in);String a[][]=new String [100][7];String id,starttime,departurepoint,destination,lasttime,fixnum,fixednum;public String input(int s){switch(s){case 0:{System.out.println("输入班次");return id=sc.next();}case 1:{System.out.println("输入起点");return departurepoint=sc.next();}case 2:{System.out.println("输入发车时间");return starttime=sc.next();}case 3:{System.out.println("输入终点");return destination=sc.next();}case 4:{System.out.println("输入行车时间");return lasttime=sc.next();}case 5:{System.out.println("输入额定载量");return fixnum=sc.next();}case 6:{System.out.println("输入已定票人数");return fixednum=sc.next();}}return id;}public void output1(){System.out.println("***--------------------------------------------------***");System.out.println(" *** ***");System.out.println(" *** 欢迎进入火车订票系统***");System.out.println(" *** ***");System.out.println("***--------------------------------------------------***");System.out.println(" || 请选择您需要的操作:||");System.out.println(" || (1)录入班次信息||");System.out.println(" || (2)查看班次信息||");System.out.println(" || (3)查询行车路线||");System.out.println(" || (4)订票||");System.out.println(" || (5)退票||");System.out.println(" || (0)退出系统||");System.out.println(" || 选择相关操作请输入相对的括号里的阿拉伯数字(0~5)! ||");public void output2(){System.out.println("班次\t\t发车时间\t起点\t\t终点\t行车时间\t额定载量\t已定票人数\n");}}class Information implements Runnable{String a[][]=new String [100][7];String x[]=new String [100];int r[]=new int [10];int b,i,g;String m;Stream sm=new Stream();Scanner sc=new Scanner(System.in);public void loop(int l){String z,s1,s2;s1="y";s2="n";int p=0;do{switch(l){case 1:in();break;case 2:search();break;case 3:order();break;case 4:delete();break;}z=sc.next();do{if(pareTo(s1)!=0&&pareTo(s2)!=0){System.out.println("指令错误!请重新输入:");z=sc.next();p=1;}elsep=0;}while(p==1);}while(pareTo(s1)==0);public void in(){int t=0,p=0;String z,u;u="admin";System.out.println("请输入管理员密码:");z=sc.next();do{if(pareTo(u)!=0){System.out.println("密码错误!请重新输入:");z=sc.next();p=1;}else{System.out.println("数据录入后请按任意键回到主菜单,继续录入请按1键");p=0;do{for(int i=0;i<7;i++){a[b][i]=sm.input(i);}b++;t=sc.nextInt();}while(t==1);}}while(p==1);System.out.println("输入成功\t信息如下:");DispAll();System.out.println("数据录入成功,想继续录入吗(y/n)");}public synchronized void order(){System.out.println("请输入您要订票的班次:");m=sc.next();boolean c=true;for(int i=0;i<b;i++){String x=a[i][0];int s=Integer.parseInt(a[i][5]);int q=Integer.parseInt(a[i][6]);if(pareTo(x)==0){c=false;if (s>q){try{Thread.sleep(10);}catch(Exception e){e.printStackTrace();}q++;System.out.println("该班次的车票已售出:"+q);a[i][6]=String.valueOf(q);}else{System.out.println("对不起,今天的这趟车的票已卖完,请明天再来,谢谢合作!\n");}System.out.println("输入成功\t信息如下:");DispAll();}}if(c==true){System.out.println("对不起,今天没有这趟车,请明天再来,谢谢使用!");}System.out.println("要继续订票吗?(y/n)");}public void run(){while(true){order();delete();}}public synchronized void delete(){System.out.println("请输入您要退票的班次:");m=sc.next();boolean c=true;for(int i=0;i<b;i++){String x=a[i][0];int q=Integer.parseInt(a[i][6]);if(q>0){if(pareTo(x)==0){c=false;q--;System.out.println("您已退票成功!");a[i][6]=String.valueOf(q);}}}if(c==true){System.out.println("对不起,今天没有这趟车或者这趟车已发出,无法完成退票!\n");}System.out.println("要继续退票吗?(y/n)");}public void search(){boolean c=true;System.out.println("===========================");System.out.println("||请选择您需要的操作: ||");System.out.println("===========================");System.out.println("||1.按班次号查询: ||");System.out.println("||2.按起点站查询: ||");System.out.println("||3.按终点站查询: ||");System.out.println("||0.退出||");System.out.println("===========================");System.out.println("||请输入您要修改的选项||:");int k=sc.nextInt();c=false;switch(k){case 1:{System.out.println("请输入班次号:");m=sc.next();for( i=0;i<b;i++){String x=a[i][0];if(pareTo(x)==0){c=false;sm.output2();for (int e=0;e<7;e++){System.out.print(a[i][e]+"\t\t\t");}System.out.println("\t");}}}break;case 2:{System.out.println("请输入起点站:");m=sc.next();for(i=0;i<b;i++){String x=a[i][2];if(pareTo(x)==0){c=false;sm.output2();for (int e=0;e<7;e++){System.out.print(a[i][e]+"\t\t\t");}System.out.println("\t");}}}break;case 3:{System.out.println("请输入终点站:");m=sc.next();for(i=0;i<b;i++){String x=a[i][3];if(pareTo(x)==0){c=false;sm.output2();for (int e=0;e<7;e++){System.out.print(a[i][e]+"\t\t\t");}System.out.println("\t");}}} break;}if(c==true){System.out.println("您要求查询的对象本来就不存在!请检查输入的正确性!");}System.out.println("要继续查询吗?(y/n)");}public void DispAll(){System.out.println("本系统的班次信息如下:");if(b==0){System.out.println("管理系统中没有录入数据或者数据已经被删除!"); }else{sm.output2();for(int i=0;i<b;i++){for (int e=0;e<7;e++){System.out.print(a[i][e]+"\t\t\t");}System.out.println("\t");}}}public void load(){Connection con ;Statement sql;ResultSet rs;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.print(e);}try{con=DriverManager.getConnection("jdbc:odbc:mydata","","");sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM ticket");while(rs.next()){for(int i=0;i<7;i++){int t=i+1;a[b][i]=rs.getString(t);}b++;}con.close();}catch(SQLException e){System.out.println(e);}r[0]=b;}public void perserve(){Connection con;PreparedStatement ps;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.print(e);}try{g=r[0];for (int h=0;h<=g;h++){con=DriverManager.getConnection("jdbc:odbc:mydata","","");ps=con.prepareStatement("UPDATE ticket SET fixednum=? WHERE id=?");ps.setString(2,a[h][0]);ps.setString(1,a[h][6]);ps.executeUpdate();ps.close();mit();con.close();}System.out.println("数据库更新完毕!");}catch(SQLException e){System.out.println(e);}}public void perserve1(){Connection con;PreparedStatement pstmt;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(ClassNotFoundException e){System.out.print(e);}try{g=r[0];for(int u=g;u<b;u++){con=DriverManager.getConnection("jdbc:odbc:mydata","","");pstmt=con.prepareStatement("INSERT INTO ticket(id,starttime,departurepoint,destination,lasttime,fixnum,fixednum) " +"V ALUES(?,?,?,?,?,?,?)");for(int i=0;i<7;i++){int t=i+1;pstmt.setString(t,a[u][i]);}pstmt.executeUpdate();pstmt.close();mit();con.close();}System.out.println("数据库添加信息完毕!");}catch(SQLException e){System.out.println(e);}}}public class hq{public static void main(String args[]){Scanner sc=new Scanner(System.in);int k=0,d,p=0;Information im=new Information();im.load();Stream sm=new Stream();String z,s1,s2;s1="y";s2="n";do{sm.output1();System.out.println("请输入选择");k=sc.nextInt();do{if(k>=0&&k<=5){d=1;}else{System.out.println("指令错误!请重新输入:");k=sc.nextInt();d=0;}}while(d==0);switch (k){case 1:{im.loop(1);im.perserve1();}break;case 2:{im.DispAll();}break;case 3:{im.loop(2);} break;case 4:{im.loop(3);im.perserve();}break;case 5:{im.loop(4);im.perserve();}break;case 0:{System.out.println("谢谢使用!");System.exit(0);}}System.out.println("您想继续进行其他操作吗?(y/n)");z=sc.next();do{if(pareTo(s1)!=0&&pareTo(s2)!=0){System.out.println("指令错误!请重新输入:");z=sc.next();p=1;}elsep=0;}while(p==1);if(pareTo(s2)==0){System.exit(0);}}while(p==0);}}。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>#define maxrailway 100#define maxorder 1000typedef struct Time{int month; //月int day; //日int hour; //小时int minute; //分钟}Time, *Ptime;typedef struct Railway{char Num[15]; //列车号char corp[15]; //铁路公司名称char rail[15]; //列车车型char from[15]; //始发站点char to[15]; //终点站Ptime takeoff; //发车时间Ptime arrive; //到站时间int price; //票价float discount; //折扣,小于100大于0的浮点数int vaculmn; //乘客容量int rest; //剩余座位数struct Railway *next;}Railway, *Pst_Rail;typedef struct Order{char Num[15]; //列车号char cusname[20]; //乘客姓名char IDcardnum[20];//乘客身份证号int ticketnum; //订票总数int num; //订单编号struct Order *next;}Order, *Pst_Order;FILE *data, *order; //分别保存列车线路记录和订单记录Pst_Rail head_rail; //列车链表表头Pst_Order head_order; //订单链表表头int flag; //退出操作的标记int numofrail; //记录列车线路数目int numoforder; //记录订单数目int lastorder; //记录最后一个订单的序号void pause(){int t, now_time;now_time = clock(); //取出当前时间for(;(t = (clock() - now_time)) < 2 * (CLOCKS_PER_SEC););system("cls"); //在pause()函数中放一个清屏函数}//时钟程序,用来控制用户界面的输出,每两个界面中间暂停2秒钟void Inuput(){int i;Pst_Rail p, q;p = head_rail;for(i = 0;i < numofrail;i++)p = p->next;q = (Pst_Rail)malloc(sizeof(Railway));q->takeoff = (Ptime)malloc(sizeof(Time));q->arrive = (Ptime)malloc(sizeof(Time));p->next = q;// 为记录开辟空间printf("Please input Railway information:\n");printf("Number:\tCorparation:\tType of railway:\n");scanf("%s%s%s",q->Num,q->corp,q->rail);//输入列车线路的车号、铁路公司名称、列车车型printf("\nPassenger vaculmn:\tTake off position:\tArrive position:\n");scanf("%d%s%s",&q->vaculmn,q->from,q->to);//输入列车的乘客容量、始发、终点q->rest = q->vaculmn;//剩余的座位初始时为乘客容量printf("\nTake off time:\tArrive time:\tPrice:\tDiscount:\nTime e.g.:6/25 12:30\n");scanf("%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->takeof f->minute);scanf("%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive->m inute);//输入列车发车的时间和到站时间scanf("%d%f",&q->price,&q->discount);//输入车票价格和折扣numofrail += 1;}void File_Scanf_Data(){Pst_Rail p, q;p = head_rail;while(!feof(data)){q = (Pst_Rail)malloc(sizeof(Railway));q->takeoff = (Ptime)malloc(sizeof(Time));q->arrive = (Ptime)malloc(sizeof(Time)); // 为记录开辟空间fscanf(data,"%s%s%s",q->Num,q->corp,q->rail);fscanf(data,"%d%s%s",&q->vaculmn,q->from,q->to);fscanf(data,"%d/%d %d:%d",&q->takeoff->month,&q->takeoff->day,&q->takeoff->hour,&q->take off->minute);fscanf(data,"%d/%d %d:%d",&q->arrive->month,&q->arrive->day,&q->arrive->hour,&q->arrive-> minute);fscanf(data,"%d%f%\n",&q->price,&q->discount);q->next = NULL;numofrail += 1;p->next = q;p = p->next;} //从文件中读取列车线路记录}void File_Scanf_Order(){Pst_Order p, q;p = head_order;while(!feof(order)){q = (Pst_Order)malloc(sizeof(Order)); // 为记录开辟空间fscanf(order,"NO.%d: %s\t%s\t%d tickets for railway :%s\n",&q->num,q->cusname,q->IDcardnum,&q->ticketnum,q->Num);q->next = NULL;numofrail += 1;p->next = q;p = p->next;} //从文件中读取订单记录}void File_write(){Pst_Rail p;Pst_Order q;p = head_rail;q = head_order;while(p->next != NULL){p = p->next;fprintf(data,"%s %s %s\n",p->Num,p->corp,p->rail);fprintf(data,"%d %s %s\n",p->vaculmn,p->from,p->to);fprintf(data,"%d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);fprintf(data,"%d/%d %d:%d",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->mi nute);fprintf(data,"%d %.2f%%\n",p->price,p->discount);}while(q->next!=NULL){q = q->next;fprintf(order,"NO.%d: %s\t%s\t%d tickets for railway :%s\n",q->num,q->cusname,q->IDcardnum,q->ticketnum,q->Num);}} //向文件中写入数据void Change_item(int n){int i, choose;Pst_Rail p;p = head_rail;for(i = 0;i < n;i++)p = p->next;printf("Which item do you want to change?\n");printf("0: Number\n1: Corparation\n2: Type of railway\n3: Passenger vaculmn\n\4: Take off position\n5: Arrive position\n6: Take off time\n7: Arrive time\n\8: Price\n9: Discount\n\n");scanf("%d",&choose);system("cls");switch(choose){case 0:{printf("The old Number is %s\nPlease input the new one:\n",p->Num);scanf("%s",p->Num);break;}//显示列车号并输入新的列车号case 1:{printf("The old Corparation is %s\nPlease input the new one:\n",p->corp);scanf("%s",p->corp);break;}//显示原铁路公司并输入新的公司名称case 2:{printf("The old Type of railway is %s\nPlease input the new one:\n",p->rail);scanf("%s",p->rail);break;}//显示原列车车型并输入新的车型case 3:{printf("The old Passenger vaculmn is %d\nPlease input the new one:\n",p->vaculmn);scanf("%d",&p->vaculmn);break;}//显示原乘客容量并输入新的容量case 4:{printf("The old Take off position is %s\nPlease input the new one:\n",p->from);scanf("%s",p->from);break;}//显示原列车始发站并输入新的站名case 5:{printf("The old Arrive position is %s\nPlease input the new one:\n",p->to);scanf("%s",p->to);break;}//显示原列车终点站并输入新的终点站case 6:{printf("The old Take off time is %d/%d %d:%d\nPlease input the new one:\n",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);scanf("%d/%d %d:%d",&p->takeoff->month,&p->takeoff->day,&p->takeoff->hour,&p->takeoff->m inute);break;}//显示原列车发车时间并输入新的时间case 7:{printf("The old Arrive time is %d/%d %d:%d\nPlease input the new one:\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minute);scanf("%d/%d %d:%d",&p->arrive->month,&p->arrive->day,&p->arrive->hour,&p->arrive->minute );break;}//显示原列车到站时间并输入新的时间case 8:{printf("The old Price is %d\nPlease input the new one:\n",p->price);scanf("%d",&p->price);break;}//显示原列车价格并输入新的价格case 9:{printf("The old Discount is %.2f%%\nPlease input the new one:\n",p->discount);scanf("%f",&p->discount);break;}//显示原车票折扣并输入新的折扣}} //由Change_main()函数调用,用来选择性地改变记录中的某一项void Change_main(){char change[15], e;Pst_Rail p, q;p = head_rail;q = head_rail;int i, flag_find;do{for(i = 0;i < numofrail;i++){p = p->next;if(p != NULL)break;}if(i == numofrail){printf("There is no railway information!\n");break;} //如果pa[]数组所有元素都为空指针则退出do...while()循环,并显示没有列车信息flag_find = 0;printf("Plese input the number of the railway you want to change:\n");scanf("%s",change);for(i = 0;i < numofrail;i++){q = q->next;if(strcmp(change,q->Num) == 0){flag_find = 1;break;}} //逐一匹配输入与数组指针指向的结构体的Num项,若相等则标记找到if(flag_find == 0){printf("No such railway exist!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'N') flag_find = 1;}system("cls");}while(flag_find == 0);do{system("cls");Change_item(i); //修改飞机线记录中的一项printf("Do you want to continue?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n'); //排除%c输入时,回车号的干扰}while(e == 'Y');}//用来查找需要修改的记录,并调用Change_item()函数void Quiry_number(){char quiry[15], e;Pst_Rail p;p = head_rail;int i, flag_quiry_number;do{system("cls");printf("Please input the number of the railway:\n");flag_quiry_number = 0;scanf("\n%s",quiry); //输入需要查询的列车号for(i = 0;i < numofrail;i++){p = p->next;if(strcmp(quiry,p->Num) == 0){system("cls");printf("Number: %s\t",p->Num);printf("From: %s\tTo: %s\n",p->from,p->to);printf("Time: %d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);printf("%d/%d %d:%d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minut e);printf("Price: %d\tDiscount: %.2f\t",p->price,p->discount);if(p->rest != 0)printf("There are %d seats avaliable!\n", p->rest);else printf("NO seat avaliable!\n");flag_quiry_number = 1;break;} //匹配输入与记录的列车号,若相同则输出列车始发站、时间以及票价、折扣和是否满座的信息}if(!flag_quiry_number){printf("There is no such railway exist!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'N') flag_quiry_number = 1;}}while(!flag_quiry_number);system("pause");} // 按照列车号查询void Quiry_position(){char quiry[2][15];Pst_Rail p;p = head_rail;int i, j, flag_quiry_position;do{printf("Please input the takeoff and arrive position of the airline:\n");flag_quiry_position = 0;scanf("%s%s",quiry[0],quiry[1]); //输入需要查询的始发、终点站名for(i = 0;i < numofrail;i++){p = p->next;if((strcmp(quiry[0],p->from) == 0) && (strcmp(quiry[1],p->to) == 0)){pause();printf("Number: %s\t",p->Num);printf("From: %s\tTo: %s\n",p->from,p->to);printf("Time: %d/%d %d:%d - ",p->takeoff->month,p->takeoff->day,p->takeoff->hour,p->takeoff->minute);printf("%d/%d %d:%d\n",p->arrive->month,p->arrive->day,p->arrive->hour,p->arrive->minut e);printf("Price: %d\tDiscount: %.2f\n",p->price,p->discount);flag_quiry_position = 1;break;}//匹配输入与记录的地点,若相同则输出始发、终点站、时间以及票价、折扣和是否满座的信息}if(!flag_quiry_position) printf("\nThere is no such airline exist!Please input again!\n");}while(!flag_quiry_position);pause();} //按照始发、终点站地点查询void Quiry_main(){char choose; //选择按照列车号还是始发、终点站查询printf("Please choose the type of quiry:\n1: Number\t2: Take off and arrive position\n");do{do{scanf("%c",&choose);}while(choose == '\n'); //排除回车的干扰system("cls");if(choose == '1'){Quiry_number(); //选择1则调用Quiry_number()函数break;}else if(choose == '2'){Quiry_position(); //选择2则调用Quiry_position()函数break;}else printf("Wrong input number!Please input again!\n");}while(1);}//用来选择查询的方式,并调用Quiry_number();或Quiry_position();void Order_main(){char ord[15];char e1;Pst_Order q, tail;Pst_Rail p;p = head_rail;tail = head_order;int i, j, flag_order; //用来标记是否存在需要预订的列车号q = (Pst_Order)malloc(sizeof(Order));//开辟空间do{flag_order = 0;e1 = 'N';printf("Please input the number of the railway:\n");scanf("%s",ord); //输入需要查询的列车号for(i = 0;i < numofrail;i++){p = p->next;if(strcmp(ord,p->Num) == 0){if(p->rest!=0){flag_order = 1; //若存在该列车且还有座位则标记为1break;}else{printf("The railway has no seat avaliable!\n");for(j = 0;j < numofrail;j++){if((strcmp(p->from,p->from)==0)&&(strcmp(p->to,p->to)==0)){if((p->rest!=0)&&(i!=j)){printf("%s: from %s to %s\n",p->Num,p->from,p->to);flag_order = -1; //标记有其他相同始末地点的列车线路}else continue;}}if(flag_order == 0){printf("There is no other railway from %s to %s",p->from,p->to);flag_order = -1;break;}else break;}}}if(flag_order == 1){system("cls");printf("%s from %s to %s, %d yuan per ticket, %d tickets avaliable.\n",p->Num,p->from,p->to,p->price,p->rest);printf("\nPlease input you name,ID number,and the amount ticket you want!\ne.g.:罗璐璐0909090825 2\n");scanf("%s%s%d",q->cusname,q->IDcardnum,&q->ticketnum);q->num = lastorder;strcpy(q->Num,ord);for(i = 0;i < numoforder;i++)tail = tail->next;tail->next = q;p->rest -= q->ticketnum;//TODO: 如果此时正好不够要定的票数numoforder += 1;lastorder += 1;printf("\nYour order number is:%d,please remember it!\n",lastorder-1);pause();}//由于在后面删除订单后不能改变其他订单的号码故此处用最后一个订单的号码+1作为新订单的号码else if(flag_order == -1){printf("Do you want to choose again?(Y/N)");do{scanf("%c",&e1);}while(e1 == '\n');}//当列车号对应列车满员时,查找相同起降点的列车线路,不管存在与否均重新输入订单号elseprintf("There is no such railway exist!Please input again!\n");//若列车号不存在则提示没有该列车号}while((flag_order == 0) || (e1 == 'Y'));}//预订车票void Cancel_order(){char e;int i, j, order, flag_cancel_order;Pst_Order q, change;q = head_order;change = q;flag_cancel_order = 0;printf("Please input the number of your order:\n");scanf("%d",&order); //吃掉回车for(i = 0;i < numoforder;i++){q = q->next;if(order == q->num){flag_cancel_order = 1;break;}}if(flag_cancel_order){printf("Are you sure?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n'); //防止误删if(e == 'Y'){for(i = 0;i < numoforder-1;i++){change = change->next;}change->next = q->next;free(q);numoforder -= 1;pause();printf("Order cacelled!\n");}}else{printf("The is no such order number!\n");printf("Do you want to try again?(Y/N)\n");do{scanf("%c",&e);}while(e == '\n');if(e == 'Y'){system("cls");Cancel_order();}}}void Print_welcome(){printf("+-----------------------------------------------------------------------+\n\+ +\n\ + +\n\ + +\n\ + 欢迎使用简易订票系统!+\n\ + +\n\ + +\n\ + +\n\ + +\n\ + Copyright @ 2011 ****** *** +\n\ + +\n\ + +\n\ +-----------------------------------------------------------------------+\n");pause();}//欢迎界面,说明程序用途及作者char Print_operate(){char e;system("cls");printf("+-----------------------------------------------------------------------+\n\+ +\n\ + 一、录入列车信息请按'1' +\n\ + +\n\ + +\n\ + 二、更改列车信息请按'2' +\n\ + +\n\ + +\n\ + 三、查询列车信息请按'3' +\n\ + +\n\ + +\n\ + 四、订票请按'4' +\n\ + +\n\ + +\n\ + 五、退票请按'5' +\n\ + +\n\ + +\n\ + 六、退出请按'6' +\n\ + +\n\ + +\n\ +-----------------------------------------------------------------------+\n");do{scanf("%c",&e);}while(e == '\n'); //不管有多少回车,全部吃掉!while((int)e < '0' || (int)e > '6'){printf("\n选择错误!请重新选择!\n");Print_operate();}return(e);}//简单操作的选择void operate(){char choice;choice = Print_operate();system("cls");switch(choice){case '1':{Inuput(); //选择1输入列车信息break;}case '2':{Change_main(); //选择2更改列车信息break;}case '3':{Quiry_main(); //选择3查询列车信息break;}case '4':{Order_main(); //选择4订票break;}case '5':{Cancel_order(); //选择5退票break;}case '6':{flag = 1; //选择6退出break;}}}int main(){head_rail = (Pst_Rail)malloc(sizeof(Railway));head_rail->takeoff = (Ptime)malloc(sizeof(Time));head_rail->arrive = (Ptime)malloc(sizeof(Time));head_rail->next = NULL;head_order = (Pst_Order)malloc(sizeof(Order));head_order->next = NULL;numofrail = 0;numoforder = 0;lastorder = numoforder + 1;Print_welcome(); //打印欢迎界面if((data = fopen("c://data.txt","r+")) == NULL){data = fopen("c://data.txt","w+");}else{printf("数据初始化,请稍后!\n");pause();File_Scanf_Data();}if((order = fopen("c://order.txt","r+")) == NULL) {order = fopen("c://order.txt","w+");}else{printf("数据初始化,请稍后!\n");pause();File_Scanf_Order();}while(1){flag = 0; //将标记置0operate(); //调用操作函数if(flag) break; //标记为1时退出}File_write();fclose(data);fclose(order);return 0;}。
航空客运订票系统源代码#include <windows.h>//dos控制命令头文件#include <iostream>//输入输出头文件#include <iomanip>//控制格式头文件#include <conio.h>//getchar()用到#include <string>//字符串函数using namespace std;//标准命名空间#define OK 1//函数结果状态码#define ERROR 0//函数结果状态码#define TRUE 1//函数结果状态码#define FALSE 0//函数结果状态码typedef int status;//函数结果状态码static int cusnum=1;//顾客数(全局变量)static int airnum=1;//航线数(全局变量)//顾客结构体struct customer{char name[9];// 顾客名char line_num[8];// 航班号int piaonum;// 座位号struct customer *next;// 下一个结点};typedef customer *Linkcustomer;//候补顾客结构体typedef struct houbuNode{//候补顾客结构体char name[9];//姓名char end_place[10];//终点站int pnum;//票数struct houbuNode *next;//指针域}* houbucustomer;struct LinkQueue{houbucustomer front,rear;//队头队尾指针};//航线结构体struct airline{char line_num[8];// 航班号char plane_num[8];// 飞机号char end_place[20];// 目的的char fly_data[20];// 飞行周日int total;// 座位总数int left;// 剩余座位Linkcustomer custom;// 订票顾客指针LinkQueue houbucus;// 候补顾客指针struct airline *next;// 下一个结点};typedef airline *Linkairline;//初始化航线链表void init_airline(Linkairline &l){l=new airline[sizeof(airline)];//产生头结点,并始l指向此头结点if(!l){//存储分配失败exit(0);//退出}l->next=NULL;//头结点的指针域为空}//初始化顾客链表(同初始化航线链表)void init_customer(Linkcustomer &l){l=new customer[sizeof(customer)];if(!l){exit(0);}l->next=NULL;}//初始化候补顾客队列链表(同初始化航线链表)void init_houbucustomer(LinkQueue &Q){Q.front=Q.rear=new houbuNode[sizeof(houbuNode)];//if(!Q.front){exit(0);}Q.front->next=NULL;}//判断airline链表是否为空status airLineEmpty(Linkairline L){if(L->next)//非空return FALSE;elsereturn TRUE;}// airline链表插入操作status insert_airline(Linkairline L,int i,char *line_num,char *plane_num,char *end_place, char *fly_data,int total,int left,Linkcustomer custom,LinkQueue houbucus){int j=0;//计数器Linkairline s,p=L;//p指向头结点while(p&&j<i-1)//寻找第i-1个结点{j++;p=p->next;}if(!p||j>i-1)//i小于1或大于表长return ERROR;//插入失败s=new airline[sizeof(airline)];//生成新结点strcpy(s->line_num , line_num);//给新结点赋值strcpy(s->plane_num , plane_num);strcpy(s->end_place , end_place);strcpy(s->fly_data , fly_data);s->total =total;s->left =left;s->custom=custom;s->houbucus=houbucus;s->next=p->next;//新结点指向原第i个结点p->next=s;//原第i-1个结点指向新结点return OK;//插入成功}// customer链表插入操作(同airline链表插入操作)status insert_customer(Linkcustomer L,int i,char *name,char *line_num,int piaonum){ int j=0;Linkcustomer s,p=L;while(p&&j<i-1){j++;p=p->next;}if(!p||j>i-1)return ERROR;s=new customer[sizeof(customer)];strcpy(s->name , name);strcpy(s->line_num , line_num);s->piaonum=piaonum;s->next=p->next;p->next=s;return OK;}// houbucustomer入队操作void insert_houbucustomer(LinkQueue &Q,char *name,char *end_place,int pnum){ houbucustomer p;p=new houbuNode[sizeof(houbuNode)];strcpy(p->name , name);strcpy(p->end_place , end_place);p->pnum=pnum;p->next=NULL;Q.rear->next=p;Q.rear=p;}// houbucustomer出队操作status del_houbucustomer(LinkQueue &Q,houbuNode &hbnode){houbucustomer p;p=Q.front->next;strcpy(,p->name);strcpy(hbnode.end_place,p->end_place);hbnode.pnum=p->pnum;Q.front->next=p->next;if(Q.rear==p)Q.rear=Q.front;delete p;return OK;}//houbucustomer输出操作void print_houbucustomer(LinkQueue Q){houbucustomer p=Q.front->next;cout<<"候补顾客为:"<<endl;cout<<"姓名终点站票数"<<endl;while(p){cout<<p->name<<" "<<p->end_place<<" "<<p->pnum;p=p->next;}cout<<endl;}// 打印航线信息status print_airline(Linkairline l){cout<<endl<<"航班号飞机号目的地飞行周日总票数余票数订票客户替补客户"<<endl;Linkairline p=l->next ;for(;p!=NULL;p=p->next ){cout<<setiosflags(ios::left)<<setw(9);cout<<p->line_num<<setw(10)<<p->plane_num<<setw(9)<<p->end_place<<setw(12)<<p->fly_data<<setw(10)<<p->total<<setw(8)<<p->left<<setw(12)<<&(p->houbucus)<<setw(10)<<&(p->custom)<<endl;}return OK;}// 打印航线信息(print_airline重载)status print_airline(Linkairline l,string name,int N){string info;bool flag=true;Linkairline p=l->next;for(;p!=NULL;p=p->next ){if(N==1)info=p->end_place;elseinfo=p->line_num;if(info==name){flag=false;cout<<endl<<"航班号飞机号目的地飞行周日总票数余票数订票客户替补客户"<<endl;cout<<setiosflags(ios::left)<<setw(9);//输出格式控制cout<<p->line_num<<setw(10)<<p->plane_num<<setw(9)<<p->end_place<<setw(12)<<p->fly_data<<setw(10)<<p->total<<setw(8)<<p->left<<setw(12)<<&(p->custom)<<setw(10)<<&(p->houbucus)<<endl;break;}}if(flag){if(N==1)cout<<"对不起,没有终点站为"<<name<<"的航班"<<endl;elsecout<<"对不起,没有航班号为"<<name<<"的航班"<<endl;}return OK;}// 打印顾客信息status print_customer(Linkcustomer l){Linkcustomer p=l->next ;for(;p!=NULL;p=p->next ){cout<<setiosflags(ios::left);//输出格式控制cout<<setw(10)<<p->name<<setw(12)<<p->line_num<<p->piaonum<<endl;}return OK;}//航班信息录入status addmoreairline(Linkairline l,Linkcustomer custom,LinkQueue houbucus){char line_num1[8],plane_num1[8],fly_data1[8],end_place1[8];int total1=100,left1=80;cout<<"请输入以下信息:"<<endl<<endl;cout<<"航班号:";cin>>line_num1;cout<<"飞机号:";cin>>plane_num1;cout<<"目的地:";cin>>end_place1;cout<<"飞行周日:";cin>>fly_data1;cout<<"总票数:";cin>>total1;cout<<"余票数:";cin>>left1;insert_airline(l,airnum,line_num1,plane_num1,end_place1,fly_data1,total1,left1,custom,ho ubucus);airnum++;cout<<"添加成功!"<<endl;print_airline(l);return OK;}// 修改airline链表中的数据status modefy_airline(Linkairline l,char *line_num){Linkairline p=l->next;for(;p!=NULL;p=p->next ){if(strcmp(line_num,p->line_num )==0){p->left++;return OK;}}cout<<"没有这个航班,无法完成修改任务!"<<endl;return ERROR;}//订票status book(Linkairline l,char *end_place,Linkcustomer c,char *name,int num,LinkQueue houbu){Linkairline p=l->next;//p指向第一个结点Linkcustomer q=c->next;//q指向第一个结点for(;p!=NULL;p=p->next)//查找{if(strcmp(end_place,p->end_place )==0){if(p->left-num >=0)//剩余票数大于订票数{cout<<"订票成功!"<<endl;insert_customer(c,cusnum,name,p->line_num,num);//向顾客链表插入记录p->left-=num;//订票成功,剩余票数减少cusnum++;//顾客数加一return OK;}else//剩余票数小于订票数{char pd;cout<<"对不起,余票不足!"<<endl;cout<<"是否需要排队候补(Y/N):";cin>>pd;if(pd=='Y'||pd=='y')//需要排队候补{insert_houbucustomer(houbu,name,end_place,num);//向候补队列插入记录cout<<"候补登记成功!"<<endl;print_houbucustomer(houbu);}else{}}return 0;}}cout<<"对不起,没有终点站为"<<end_place<<"的航班!"<<endl;return ERROR;}//退票status delete_cus(Linkcustomer h,Linkairline l,char *name,LinkQueue houbu){Linkcustomer p=h->next,pr=h;//p指向顾客链表首结点char line_num[8];houbuNode hbnode;while(p!=NULL)//循环查找退票顾客{if(strcmp(name,p->name )==0){strcpy(line_num,p->line_num );for(int i=0;i<p->piaonum;i++)//更改该航线的剩余票数modefy_airline(l,line_num);pr->next =p->next ;cout<<"顾客"<<p->name<<"退票成功!"<<endl;cusnum--;//顾客数减一if(houbu.front->next==NULL){}else{del_houbucustomer(houbu,hbnode);//候补顾客出队if(l->next->left>=hbnode.pnum)//剩余票数多于排在第一位的客户订的票数{//为排在第一位的客户办理订票业务book(l,hbnode.end_place,h,,hbnode.pnum,houbu);cout<<"候补顾客"<<<<"订票成功!"<<endl;}else//剩余票数少于排在第一位的客户订的票数{cout<<"票数仍然不足!";}}return OK;}pr=pr->next ;p=pr->next ;}cout<<"无此顾客,无法退票!"<<endl;//未查到顾客信息return ERROR;}//打开进度条,程序信息简介void open(){cout<<"\n\n\n\n 课程设计\n";cout<<"\n ╔-------------------------------╗";cout<<"\n ││";cout<<"\n │名称: 航空订票系统│";cout<<"\n ││";cout<<"\n │作者: 乐升平│";cout<<"\n ││";cout<<"\n │学号: 201210510216 │";cout<<"\n ││";cout<<"\n │班级:12计科(2)班│";cout<<"\n ││";cout<<"\n │工具: VC++6.0 C++语言│";cout<<"\n ││";cout<<"\n ╚-------------------------------╝\n";system("pause");system("cls");cout<<"\n\n\n\n\n\n ****************欢迎使用航空订票系统**************\n\n\n";const int M=25;int k;cout<<"\n 〓程序加载中>>>> ";for (k=1;k<=M;k++){cout<<"■";Sleep(100);}system("cls");cout<<endl<<"【载入完成】\a"<<endl<<endl;cout<<" 前言"<<endl<<endl;cout<<" 欢迎使用『航空订票系统』,本程序实现了以下功能:\n\n";cout<<" ①录入功能:可以录入航班情况\n\n";cout<<" ②查询功能:根据客户提供的终点站名或航班号进行查询。
#include <iostream.h>#include <string.h>void FlightInsert(); //增加路线void FlightDelete();//删除路线void FlightLookup();//航班查询void FlightRework();//航班路线修改void FlightBuyticket();//买票void FlightCancelticket();//取消订票void Flightclean();//清空void MainMenu();//主函数void Display();//显示订票信息typedef struct Customer //已定票乘客信息{char Name[10]; //姓名int Amount; //定票数int Level; //舱位等级int SeatNum; //座位号char FlightNum[10]; //所定航班号struct Customer *next;}Customer;typedef struct Replace //侯补乘客信息{char Name[10]; //姓名eint Amount; //定票数int Level; //舱位等级char FlightNum[10]; //所定航班号struct Replace *next;}Replace;typedef struct Flight //航班路线信息{char From[10]; //起点站名char Des[10]; //终点站名char FlightNum[10]; //航班号char PlaneNum[10]; //航班char Week[20]; //飞机周日int Ration; //乘员定额int FreeTicket; //剩余票数float Price[3]; //票价int ReplacePas; //候补乘客数Replace *ReplName; //该航班的候补乘客名单Customer *CustName; //该航班的已定票乘客名单struct Flight *next; //指示下一航班路线结点}Flight,*PFlight;int Ration=0; //乘客总数Flight *head; //建立航班路线头结点Flight *rear; //建立航班路尾结点Customer *Cusrear;Replace *Reprear;void MainMenu(){int i=0;while (i!=8){cout<<endl;cout<<" ***************【欢迎使用航空订票系统】***************"<<endl;cout<<" "<<endl;cout<<" ***************【按1】增加航班路线***************"<<endl;cout<<" "<<endl;cout<<" ***************【按2】查询航班路线***************"<<endl;cout<<" "<<endl;cout<<" ***************【按3】修改航班路线***************"<<endl;cout<<" "<<endl;cout<<" ***************【按4】预订飞机票***************"<<endl;cout<<" "<<endl;cout<<" ***************【按5】退订飞机票***************"<<endl;cout<<" "<<endl;cout<<" ***************【按6】清空系统***************"<<endl;cout<<" "<<endl;cout<<" ***************【按7】已订票名单***************"<<endl;cout<<" "<<endl;cout<<" ***************【按8】退出系统***************"<<endl;cout<<" "<<endl;cout<<" *提示:当前为主菜单"<<endl;cin>>i;switch(i){case 1:FlightInsert();break; //增加航班路线case 2:FlightLookup();break; //查询航班路线case 3:FlightRework();break; //修改航班路线case 4:FlightBuyticket();break; //预订飞机票case 5:FlightCancelticket();break; //退订飞机票case 6:Flightclean();break; //清空系统case 7:Display();break;case 8:;break;default:cout<<"*提示:抱歉,请选择正确的操作!"<<endl;cout<<endl;cout<<endl;break;}}}void FlightInsert() //航班录入{/*int i=2;while(i!=1){*/Flight *p;p=new Flight;cout<<"****正在设定新的路线****"<<endl;cout<<endl;cout<<"1.请设定起点站名:"<<endl;cin>>p->From;cout<<"2.请设定终点站名:"<<endl;cin>>p->Des;cout<<"3.请设定航班号:"<<endl;cin>>p->FlightNum;cout<<"4.请设定飞机号:"<<endl;cin>>p->PlaneNum;cout<<"5.请设定飞行周日:"<<endl;cin>>p->Week;cout<<"6.请设定乘员定额:"<<endl;cin>>p->Ration;p->FreeTicket=p->Ration;cout<<"7.请设定一等舱的价格:"<<endl;cin>>p->Price[0];cout<<"8.请设定二等舱的价格:"<<endl;cin>>p->Price[1];cout<<"9.请设定三等舱的价格:"<<endl;cin>>p->Price[2];p->ReplName=new Replace;p->CustName=new Customer;p->CustName->next=NULL;p->ReplName->next=NULL;p->ReplacePas=0;rear->next=p;rear=p;rear->next=NULL;cout<<"设置成功!"<<endl;cout<<"***********************"<<endl;cout<<endl;/*cout<<"【按1】返回主菜单【按2】继续"<<endl;cin>>i;}*/}void FlightLookup() //查询航班号{Flight *p,*q;char FlightNum[10];p=head;int i=0;while (i!=1){cout<<"请输入需要查询的航班号:"<<endl;cin>>FlightNum;while (p->next && strcmp(p->next->FlightNum,FlightNum)){p=p->next;}q=p->next;if (q==NULL){cout<<"*提示:对不起,不存在此航班号,请核实您的信息!"<<endl;}else{cout<<"以下是您所查的车次信息:"<<endl;cout<<"************************"<<endl;cout<<"* 1.航班号: "<<q->FlightNum<<endl;cout<<"* 2.飞机号: "<<q->PlaneNum<<endl;cout<<"* 3.起点站: "<<q->From<<endl;cout<<"* 4.目的地: "<<q->Des<<endl;cout<<"* 5.飞机周日: "<<q->Week<<endl;cout<<"* 6.成员定额: "<<q->Ration<<endl;cout<<"* 7.剩余票数: "<<q->FreeTicket<<"张"<<endl;cout<<"* 8.候补乘客数: "<<q->ReplacePas<<"人"<<endl;cout<<"* 9.一等舱的价格: "<<q->Price[0]<<"元"<<endl;cout<<"* 10.二等舱的价格: "<<q->Price[1]<<"元"<<endl;cout<<"* 11.三等舱的价格: "<<q->Price[2]<<"元"<<endl;cout<<"************************"<<endl;}cout<<"您还需要其他的操作么?"<<endl;cout<<endl;cout<<"【按1】返回主菜单【按2】继续操作"<<endl;cin>>i;cout<<"************************"<<endl;cout<<endl;}}void FlightRework() //修改航班路线信息{int Customer_Number ;Flight *p,*q;char FlightNum[10];int i=0;int a=1;p=head;cout<<"请输入需要修改的航班:"<<endl;cin>>FlightNum;while (p->next&&strcmp(p->next->FlightNum,FlightNum)){p=p->next;}q=p->next;if (q==NULL){cout<<"*提示:对不起,不存在此航班,请核实您的信息!"<<endl;}else{while(a){cout<<" *******【请输入需要修改的数据】*******"<<endl;cout<<" "<<endl;cout<<" 【按1】航班号 "<<endl;cout<<" "<<endl;cout<<" 【按2】飞机号 "<<endl;cout<<" "<<endl;cout<<" 【按3】起始站 "<<endl;cout<<" "<<endl;cout<<" 【按4】目的地 "<<endl;cout<<" "<<endl;cout<<" 【按5】每周出站日期 "<<endl;cout<<" "<<endl;cout<<" 【按6】成员定额 "<<endl;cout<<" "<<endl;cout<<" 【按7】一等舱的价格 "<<endl;cout<<" "<<endl;cout<<" 【按8】二等舱的价格 "<<endl;cout<<" "<<endl;cout<<" 【按9】三等舱的价格 "<<endl;cout<<" "<<endl;cout<<" 【按10】退出 "<<endl;cout<<" "<<endl;cout<<" **************************************"<<endl;cin>>i;switch(i){case 1:cout<<"1.请输入航班号:"<<endl;cin>>q->FlightNum;break;case 2:cout<<"2.请输入飞机号:"<<endl;cin>>q->PlaneNum;break;case 3:cout<<"3.请输入起始站:"<<endl;cin>>q->From;break;case 4:cout<<"4.请输入目的地:"<<endl;cin>>q->Des;break;case 5:cout<<"5.请输入飞机周日:"<<endl;cin>>q->Week;break;case 6:cout<<"6.请输入乘员定额:"<<endl;Customer_Number=q->Ration-q->FreeTicket;cin>>q->Ration;q->FreeTicket=q->Ration-Customer_Number;break;case 7:cout<<"7.请输入一等舱的价格:"<<endl;cin>>q->Price[0];break;case 8:cout<<"8.请输入二等舱的价格:"<<endl;cin>>q->Price[1];break;case 9:cout<<"9.请输入三等舱的价格:"<<endl;cin>>q->Price[2];break;case 10:a=0;break;default:cout<<"*提示:对不起,请选择正确的操作!"<<endl;cout<<endl;cout<<endl;break;}}}}void FlightBuyticket() //订票{int Ticket_Amount;void Buyticket(PFlight ,int );void Buyreplace(PFlight ,int ,int );Flight *p,*q;char Des[10];int i=2;while (i!=1){cout<<"请输入目的地:"<<endl;cin>>Des;p=head;while (p->next&&strcmp(p->next->Des,Des)){p=p->next;}q=p->next;if (q==NULL){cout<<"*提示:对不起,不存在此航班,请核实您的信息!"<<endl;}else{while(i!=1){cout<<"请输入需要购买的票数:"<<endl;cin>>Ticket_Amount;while(Ticket_Amount==0 && Ticket_Amount<0){cout<<"*提示:对不起,请输入正确的票数!"<<endl;cout<<endl;cout<<"请输入需要够买的票数:"<<endl;cin>>Ticket_Amount;}if (Ticket_Amount<=q->FreeTicket){Buyticket(q,Ticket_Amount);}else{int n;cout<<"*提示:抱歉!剩余票数小于定票数,是否需要列入候补名单?(【按1】是【按2】否)"<<endl;cin>>n;Buyreplace(q,Ticket_Amount,n);}cout<<endl;cout<<"【按1】返回主菜单【按2】继续"<<endl;cin>>i;}}}}void FlightCancelticket() //退票{void Buyticket(PFlight ,int );Flight *p,*q;Customer *h,*j;char FlightNum[6];char Customer_Name[10];int Replace1_Amount; //候补第一个人的定票数int i;cout<<"**********************************"<<endl;while (i!=1){cout<<"请输入需要退定的航班号:"<<endl;cin>>FlightNum;p=head;while (p->next&&strcmp(p->next->FlightNum,FlightNum)){p=p->next;}q=p->next;if (q==NULL){cout<<"*提示:对不起,不存在此航班,请核实您的信息!"<<endl;}else{while (i!=2){cout<<"请输入所查姓名:"<<endl;cin>>Customer_Name;h=q->CustName;while (h->next&&strcmp(h->next->Name,Customer_Name)){h=h->next;}j=h->next;if(j==NULL){cout<<"*提示:对不起,查无此人,请核实您的信息!"<<endl;cout<<endl;}else{if(j->next==NULL){ //当删除最后一个结点Cusrear=h;}h->next=h->next->next;q->FreeTicket+=j->Amount;delete j;cout<<"*提示:退票成功!"<<endl;if(q->ReplName->next!=NULL){Replace1_Amount=q->ReplName->next->Amount;if (Replace1_Amount<=q->FreeTicket){Replace *rep;rep=q->ReplName->next;Customer *Cus2;Cus2=new Customer;Cus2->SeatNum=q->Ration-q->FreeTicket+1;strcpy(Cus2->FlightNum, q->FlightNum );strcpy(Cus2->Name, rep->Name );Cus2->Amount=rep->Amount;Cus2->Level=rep->Level;cout<<"*提示:"<<endl;cout<<endl;cout<<"候补乘客:"<<rep->Name<<" 已经成功买票!"<<endl;cout<<endl;cout<<"航班号:"<<Cus2->FlightNum<<endl;cout<<"舱位等级为:"<<rep->Level<<"(1一等舱,2二等舱,3三等舱)"<<endl;cout<<"座位号为:"<<endl;for(int i=1;i<=(rep->Amount);i++){cout<<"No."<<Cus2->SeatNum++<<" ";}cout<<endl;if (q->CustName->next==NULL){Cusrear=q->CustName;Cusrear->next=Cus2;Cusrear=Cus2;Cusrear->next=NULL;}else{Cusrear->next=Cus2;Cusrear=Cus2;Cusrear->next=NULL;}q->FreeTicket-=rep->Amount;q->ReplName->next=q->ReplName->next->next;q->ReplacePas--;delete rep;}}}break;}}cout<<"【按1】返回主菜单,或按任意键返回【继续退票操作】!"<<endl;cout<<endl;cin>>i;}}void Flightclean()//清空{head->next=rear->next;cout<<"*提示:系统已经清空!"<<endl;cout<<endl;}void Buyticket(PFlight q,int Ticket_Amount) //买票{int n=Ticket_Amount;Customer *Cus2;Cus2=new Customer;Cus2->SeatNum=q->Ration-q->FreeTicket+1;strcpy(Cus2->FlightNum, q->FlightNum );Cus2->Amount=Ticket_Amount;cout<<"1.请输入姓名:"<<endl;cin>>Cus2->Name;cout<<"2.请输入购买票的类型:"<<endl;cout<<"【按1】一等舱,【按2】二等舱,【按3】三等舱"<<endl;cin>>Cus2->Level;cout<<"*提示:订票成功!"<<endl;cout<<endl;cout<<"舱位等级:"<<" "<<Cus2->Level<<endl;cout<<"座位号为:"<<endl;for(int i=1;i<=Ticket_Amount;i++){cout<<"No."<<Cus2->SeatNum++<<" ";}cout<<endl;if (q->CustName->next==NULL){Cusrear=q->CustName;Cusrear->next=Cus2;Cusrear=Cus2;Cusrear->next=NULL;}else{Cusrear->next=Cus2;Cusrear=Cus2;Cusrear->next=NULL;}q->FreeTicket-=Ticket_Amount;}void Buyreplace(PFlight q,int Ticket_Amount,int n) //进入候补队列{Replace *Rep2;Rep2=new Replace;if(n==1){q->ReplacePas+=Ticket_Amount;strcpy(Rep2->FlightNum,q->FlightNum);Rep2->Amount=Ticket_Amount;cout<<"1.请输入姓名:"<<endl;cin>>Rep2->Name;cout<<"2.请输入购买票的类型:"<<endl;cout<<"【按1】一等舱,【按2】二等舱,【按3】三等舱"<<endl; cin>>Rep2->Level;if(q->ReplName->next==NULL){Reprear=q->ReplName;Reprear->next=Rep2;Reprear=Rep2;Reprear->next=NULL;}else{Reprear->next=Rep2;Reprear=Rep2;Reprear->next=NULL;}}}void Display()//显示订票信息{cout<<"*提示:抱歉,该项目还在开发!"<<endl;cout<<endl;int i;cout<<"【按1】返回至主菜单"<<endl;cin>>i;while(i=1){break;}/*Customer *h,*j;char Customer_Name[10];int i;while (i!=2){cout<<"请输入所查姓名:"<<endl;cin>>Customer_Name;h=q->CustName;while (h->next&&strcmp(h->next->Name,Customer_Name)){h=h->next;}j=h->next;if(j==NULL){cout<<"*提示:对不起,查无此人,请核实您的信息!"<<endl;cout<<endl;}else{cout<<}*///Customer *p;//cout<<"已买票的乘客有:"<<endl;//cout<<endl;//cout<<"姓名:"<<p->Name<<"航班号:"<<p->FlightNum<<"订票数:"<<p->Amount<<endl;//cout<<"舱位等级:"<<p->Level<<"座位号"<<p->SeatNum;//Flight *q;//char FlightNum[10];//cout<<"以下是您所查的车次信息:"<<endl;//cout<<"************************"<<endl;//cout<<"* 姓名: "<<q->Name<<endl;//cout<<"* 航班号: "<<q->FlightNum<<endl;//cout<<"* 飞机号: "<<q->PlaneNum<<endl;//cout<<"* 起点站: "<<q->From<<endl;//cout<<"* 目的地: "<<q->Des<<endl;//cout<<"* 飞机周日: "<<q->Week<<endl;//cout<<"* 舱位等级: "<<q->Level<<endl;}******************************************************************************************************#include "AirLineSystem.h" #include<iostream.h>void main() //主程序{Cusrear=new Customer;Reprear=new Replace;head=rear=new Flight;head->next=NULL;MainMenu();}。
最新航班舱位代码表
小常识:飞机舱位分为3类,F舱为头等舱;C为公务舱;Y为经济舱。
以上折扣舱位是经济舱位的一种,只是航空公司为划分价格而划分的舱位,与一般经济舱位一样。
一ETERM进入
1 工作好进入 SI:工作号/密码
2 工作号退出 SO:
3 修改密码AM:旧密码/新密码SO: SI:
二查询指令(昨天- 今天·明天+)
1 指定日期航班AVH/城市对/日期/航空公司
2 只要直飞AVH/城市对/日期/D/航空公司
3 查询经停点FF:航班号/日期
4 返程查询AV/RA/日期
5 航班一周情况SK:(城市对)
6 国内公布票价FD:城市对/日期/航空公司
7 查询特价N FD:城市对/日期/航空公司
8 提取历史纪录RT编码RTU1
9 地方运输航段SA:城市对
10 不定期航段SN:航空公司/舱位/城市对
三订座记录
1 姓名
①中国成人:名字1名字
②外籍成人:NM1姓/名(不能超过26个字母)
③中国成人票:姓/名(拼音)
④儿童:名字CHD
⑤婴儿:XN:IN/名字INF(出生月年)/跟随大人序号
2 航段
①直接订座SS:航空公司航班号仓位日期城市对座位数
②间接订座
AVH/城市对/日期/航空公司
SD/序号/仓位/人数
3 联系组
①T:电话
②OSI YY CTCT电话
4 时限组
TKTL/时间/日期/办公号
5证件
SSR FOID YY HK/NI证件号/P对应的序号
6 备注
RMK
签注:EI签注内容
7 PNR生效
①或I 正常情况下封口
②I在两地断开,转移时间段,同一城市不同一场
③@K行动代码有变化的情况下
④I或IG放弃操作
⑤\KI强行口
四提取记录
1 查询已有订单号 RT:PNR
2 查询姓名所属单号 TR:名字/航班号/日期
3 查询指定日期航班的ML:C/航班号/日期
4 AB/起飞日期/城市对
5 提取历史文件 RT:C/PNR
6 大编码转换小编码 RRT V/PNR/0000/日期五ETDZ 出票
1 RT:PNR
2 航段序号RR
3 XE时限组
4 ①PAT:A(成人)②PAT:A*CH(儿童)③PAT:A*IN(婴儿)
5 ETDZ 打印机号
6 票价计算
①FC:起飞城市承运人到达城市票价仓位CNY 票面总价END
②FP:CASH,CNY(婴儿IN/CASH,CNY
③FN:FNCY票面价、SCNY销售价/C代理费/TCNY机场建设费CN/TCNY燃油YQ
7 电脑错误情况下重出票(出票未成功)
①XE 以出票标记
②补充缺少项
③ETRY(冲出票指令)
六查询编码与计算
1 根据城市查三字代码 CNTD:T/城市(拼音)
2 根据城市代码查城市名字CD:三字代
3根据国家代码查国家名字CNTD:C/二字代码
4 计算公式 CO:
5 时差 CO:T城市对
6 天数计算 DATE:日期/天数
7 天气查询 WF:三字代码
8 长度、重量、温度换算 CV:
①千米KM ②英里MI ③摄氏C ④华氏F ⑤英镑LB ⑥公斤KG
七修改PNR记录
1删除
①出姓名以外的其他内容XE序号
②删除姓名 XEP序号
③删除记录 XEPNR\工作号
2 调整航班 CS:序号/序号(相邻两段)
3 添加航段 ES:(在后补的状态下有位子)
4 分离 SP:序号(分离的人)
八团退记录(10人以上成团对)
1团名CN:人数团名(其余和散客订座一样,可以先不输入名字)
2 团队提取
①只显示名字填写总数、不现实具体名字RT团队/航班/日期
②现实具体名字 TR:N/PNR
3 团队分离
①已输入旅客姓名SP:序号
②未输入旅客姓名SP:G座位数
③两者同事分离SP:G座位数/P序号
九通过电脑给手机发短信
1 RTPNR
2 RMK MP 手机号\
3 RTPNR
4 SMS:I编码\
十电子客票(ET)
1查询授权信息DDI:
2 打票机状太DI:打票机号
3 打票机设置
①建立打票机控制EC打票机号TI打票机号
②退出打票机控制XC打票机号
4 输入票号
①查询票号 TOL:
②上票号 TN:打票机号X/起始票号——结束票号后五位数
十一提取票号信息
1 DETR:TN/票号
2 DETR:NI/证件号
3 DETR:NM/名字
4 DETR:CN/大编码(如果人数多不一定能显示)
5 显示全部旅客信息 DETR:CN/大编码,C
6 只提取这个旅客的证件号DETR:票号,F
7 提取这张票的历史 DETR:票号,H
8 提取出票信息 DETR:票号,S
9 提取这个票号的所有订票记录 DETR:CN/PNR,F
十二改签(不引起票面变化、不变更航空公司)
1 提记录 RT:PNR
2 做新航段 AVH/城市对/日期/航空公司
3 XE票价组
4 XE旧航段
5 封口(\I)
6 新航段做RR
7 SSR TKNE YY HK1 城市对航班号仓位日期票号/1/P对应人的序号十三改证件
1 XE 旧证件号
2 SSR FOID YY HK/NI证件号
十四废票
1 查看客票出票时间(当天出的、票号OPEN、进控)
2 VT:打印机号/起始票号——结束票号后五位/PNR(小编码)
十五退票
1 自动退票
①查看票号状态(票号OPEN状态)
②TRFD:L/票号/AM/打印机号/D
③在左下角输入E确定
①
②
④TRFD:H/打印机号/D/退票单号
2 手工退票
①TRFD:AM/打印机号/D
手续费票面价票号
①
CN 机场建设费燃油费总和代理费(3.00) 0改成1 ②
十六挂起与解挂
1 挂起TSS:TN/票号/S TSS:CN/大编码/S
2 挂起TSS:TN/票号/B TSS:CN/大编码/B
十七销售报表
1 正常出票TSL:C/打票机号/工作号
2 出票总数TSL:F/打票机号/工作号
3 退票TSL:R/打票机号/工作号
4 废票TSL:V/打票机号/工作号
十八客票状太与机票状态
1 客票状态
①OPRN FOR USE 开放使用
②USED/FLOWN 已使用
③CHECK IN 已办理登记手续
④REFOUND 已退票
⑤SUSPENDED 客票被挂起,无法使用
⑥FIM EXCH 被换开中断仓单
⑦PRINT EXCH 被换开纸票
⑧VOID 已作废
2 机票状态
①HK或DK是座位预定成功
②RR是已出票
③NN.NO.DW.NW是没有预定成功
④NO是位子被航空公司取消
⑤HK或DK是座位预定成功
⑥RR是已出票或者说是座位已经订死状态
⑦NN.DW.NW.HL.HN.SS是没有预定成功
8 NO是位子被航空公司取消
9 KK、KL控制室给K予的位置
十九恢复退票
1 TSL:R/打票机号/工作号
2 TRFD:M/打票机号/D/退票单号
3 U改成X
4 ETRF:航段序号/票号/PRNT/打票机号/OPEN
出现**ET.REFUND CANELED**
十二其他指令
1 手工退票TRFD:AM/打票机号/D
2 手工输价PAT:
3 换编码出(在RT基础上)CYY
4 时限项出现假票号时限项WC/./PEK01 XE时限项
5 海航A舱输入 OSI HU CKIN SSAC/SI
6 积分卡号 SSR:FQTV YY HK/YY卡号
7 Q箱QSSC Q/V Q/VE
Eterm出现英文输入CVOF
二十一婴儿票
1 RT:PNR(大人)
2 XN:IN/中文名字INF(月年)/P1
3 SSR INFT YY NN1 城市对航班号仓位日期姓/名出生日月年/P1
4 时限组序号T/票号
5 \I
6 XE实现组
7 PAT:A*IN
8 ETDZ 3,INF
二十二月份和星期缩写
JAN 一月FEB 二月 MAR 三月 APR 四月
MAY 五月JUN 六月 JUL 七月 AUG 八月
SEP 九月OCT 十月 NOV 十一月 DEC 十二月
SUN 星期日MON 星期一TUE 星期二WED 星期三
THU 星期四FRI 星期五 SAT 星期六。