#include #include using namespace std; int ynf(int a,int t){ //比较两整数值; int x; if(a==t) x=1; else x=0; return x; } int cmp(string a,string b){ //比较两字符串; int x; if(a!=b) x=0; else x=1; return x; } void exchange(string &a,string &b){ string c; c=b; b=a; a=c; } void main(){ int addflight; //定义增加的航班号; string addorigin; //定义增加的航班对应的起始站; string addfinishpoint;//定义增加的航班对应的终点站; string addsetouttime;//定义增加的航班对应的出发时间; int choice; //定义全局变量; int addnum;//定义增加的航班对应的票数; int price; //定义票价; int in_flight; //定义输入的航班; char zh; zh='n'; //初始化zh; int flightnum=0; //初始化航班总数; string b[299]; //定义全局变量字符串数组; int a[299]; //定义全局变量整型数组; while('Y'!=zh){ //订票系统; char j='Y'; cout<<\"***********************************\"< cin>>choice; switch(choice){ case 1:flightnum++; //每执行一次增加航班信息,航班总数数加1; cout<<\"请输入增加的航班号:\"; cin>>addflight; cout<<\"请输入增加的起始站:\"; cin>>addorigin; cout<<\"请输入增加的终点站:\"; cin>>addfinishpoint; cout<<\"请输入增加的起飞时间:\"; cin>>addsetouttime; cout<<\"请输入增加的的票数:\"; cin>>addnum; cout<<\"请输入票价:\"; cin>>price; a[(flightnum-1)*3]=addflight; b[(flightnum-1)*3]=addorigin; b[(flightnum-1)*3+1]=addfinishpoint; b[(flightnum-1)*3+2]=addsetouttime; a[(flightnum-1)*3+1]=addnum; a[(flightnum-1)*3+2]=price; break; case 2: //浏览航班信息; { cout<<\"您所浏览的航班信息为:\"< cout< break; case 3: //查找航班信息; while('Y'==j){ int choice1; //定义一局部变量; cout<<\" 1 按航班号查询 \"< cin>>choice1; switch(choice1){ case 1: //按航班号查询; { cout<<\"请输入航班号:\"; cin>>in_flight; cout<<\"您所查找的航班信息为:\"< for(int i=1;i<=flightnum;i++){ //循环对比航班号; int w=ynf(in_flight,a[(i-1)*3]); //调用函数ynf(); switch(w){ case 1: cout< case 0: noexistnum++; break; } } if(noexistnum==flightnum){ cout<<\"您所查找的航班号不存在\"< cout<<\"是否继续查找(Y/N)? \"; cin>>j; } break; case 2: //按终点站查询; string in_finishipoint; //定义字符串变量; cout<<\"请输入终点站:\"; cin>>in_finishipoint; cout<<\"您所查找的航班信息为:\"< for(int qw=1;qw<=flightnum;qw++){ int w=cmp(in_finishipoint,b[(qw-1)*3+1]); switch(w){ case 1: cout< case 0: nonum++; break; } } if(nonum==flightnum){ cout<<\"您所查找的航班号不存在\"< cout<<\"是否继续查找(Y/N)? \"; cin>>j; break; } } break; case 4: //按航班号排序; while('Y'==j){ int choice2; cout<<\" ********************** \"< cin>>choice2; switch(choice2){ case 1: // 按航班号从小到大排序; { for(int kh=1;kh if(a[(i-1)*3]>=a[i*3]){ z=a[i*3]; a[i*3]=a[(i-1)*3]; a[(i-1)*3]=z; exchange(b[(i-1)*3],b[i*3]); k=a[i*3+1]; a[i*3+1]=a[(i-1)*3+1]; a[(i-1)*3+1]=k; exchange(b[(i-1)*3+1],b[i*3+1]); g=a[i*3+2]; a[i*3+2]=a[(i-1)*3+2]; a[(i-1)*3+2]=g; exchange(b[(i-1)*3+2],b[i*3+2]); } } } cout<<\"您所排序的的信息为:\"< cout< cin>>j; } break; case 2: // 按航班号从大到小排序; { for(int k1=1;k1 if(a[(i-1)*3]<=a[i*3]){ zy=a[i*3]; a[i*3]=a[(i-1)*3]; a[(i-1)*3]=zy; exchange(b[(i-1)*3],b[i*3]); ky=a[i*3+1]; a[i*3+1]=a[(i-1)*3+1]; a[(i-1)*3+1]=ky; exchange(b[(i-1)*3+1],b[i*3+1]); gy=a[i*3+2]; a[i*3+2]=a[(i-1)*3+2]; a[(i-1)*3+2]=gy; exchange(b[(i-1)*3+2],b[i*3+2]); } } } cout<<\"您所排序的的信息为:\"< cout< cout<<\" ********************** \"< cin>>j; } break; } } break; case 5: //订票; while('Y'==j){ cout<<\"请输入订票的航班号:\"; cin>>in_flight; cout<<\"您所订购的航班信息为:\"< for(int i=1;i<=flightnum;i++){ int ordernum; //定义订购的机票数; int w=ynf(in_flight,a[(i-1)*3]); switch(w){ case 1: cout< cin>>ordernum; if(ordernum>a[(i-1)*3+1]) cout<<\"没有足够的票数\"< cout<<\"订票成功\"< } break; case 0: noexnum++; break; } } if(noexnum==flightnum){ cout<<\"您所查找的航班号不存在\"< cout<<\"是否继续订票(Y/N)? \"; cin>>j; } break; case 6: while('Y'==j){ cout<<\"请输入退票的航班号:\"; cin>>in_flight; cout<<\"您所退订的航班信息为:\"< for(int i=1;i<=flightnum;i++){ int refundnum; //定义退订的机票数; int w=ynf(in_flight,a[(i-1)*3]); //调用比较函数; switch(w){ case 1: cout< cin>>refundnum; a[(i-1)*3+1]+=refundnum; cout<<\"退票成功\"< case 0: noexinum++; break; } } if(noexinum==flightnum){ cout<<\"您所查找的航班号不存在\"< cout<<\"是否继续退票(Y/N)? \"; cin>>j; } break; case 7: //是否退出系统; cout<<\"是否退出订退票系统(Y/N) \"; cin>>zh; break; } } } 因篇幅问题不能全部显示,请点此查看更多更全内容