我们的课程设计题目,要求能够对航班信息进行排序和查询,按航班号,起点站,到达站,起飞时间,到达时间查询。
我用的是c++,想问一下航班信息是不是用数据库存起来啊?那怎么和C++联系起来啊?我想用很笨的方法,就是自己建一个结构体然后手动的输入航班信息,这样行么?还有,这个是用链式存储比较好还是顺序存储呢?感觉链式存储排序不太方便,但循序存储我不太懂在一个结点里包含什么航班号阿,起点站阿等这些信息,结构体怎么定义阿?大家救救我啊
我编了个程序,但错误好多,帮我看看吧,好像是字符串那有问题。
#include<iostream>
#include<string>
#define N 20
using namespace std;
struct flight{
int flightnumber; //航班号
int starttime; //起飞时间
int arrivedtime; //到达时间
char start[10]; //起飞站
char arrived[10]; //终点站
char date[10];
}flight[N];
void flightinfo() //航班信息
{
int i=1;
flight[i].flightnumber=1351;
flight[i].starttime=0750;
flight[i].arrivedtime=1055;
flight[i].start[]="beijing";
flight[i].arrived[]="guangzhou";
i++;
flight[i].flightnumber=4951;
flight[i].starttime=1320;
flight[i].arrivedtime=1510;
flight[i].start[]="hangzhou";
flight[i].arrived[]="guilin";
i++;
flight[i].flightnumber=6101;
flight[i].starttime=0800;
flight[i].arrivedtime=0910;
flight[i].start[]="shenyang";
flight[i].arrived[]="beijing";
i++;
flight[i].flightnumber=3907;
flight[i].starttime=0820;
flight[i].arrivedtime=1020;
flight[i].start[]="beijing";
flight[i].arrived[]="shanghai";
i++;
flight[i].flightnumber=6132;
flight[i].starttime=0830;
flight[i].arrivedtime=0930;
flight[i].start[]="beijing";
flight[i].arrived[]="dalian";
i++;
flight[i].flightnumber=1343;
flight[i].starttime=0745;
flight[i].arrivedtime=1005;
flight[i].start[]="beijing";
flight[i].arrived[]="changsha";
i++;
flight[i].flightnumber=2416;
flight[i].starttime=1725;
flight[i].arrivedtime=1925;
flight[i].start[]="beijing";
flight[i].arrived[]="lanzhou";
i++;
flight[i].flightnumber=1534;
flight[i].starttime=1055;
flight[i].arrivedtime=1240;
flight[i].start[]="shanghai";
flight[i].arrived[]="tianjin";
i++;
flight[i].flightnumber=2508;
flight[i].starttime=1240;
flight[i].arrivedtime=1420;
flight[i].start[]="shanghai";
flight[i].arrived[]="wuhan";
i++;
flight[i].flightnumber=5816;
flight[i].starttime=0800;
flight[i].arrivedtime=1100;
flight[i].start[]="shanghai";
flight[i].arrived[]="kunming";
i++;
flight[i].flightnumber=9247;
flight[i].starttime=1910;
flight[i].arrivedtime=2030;
flight[i].start[]="shanghai";
flight[i].arrived[]="jinan";
i++;
flight[i].flightnumber=5260;
flight[i].starttime=1305;
flight[i].arrivedtime=1540;
flight[i].start[]="guangzhou";
flight[i].arrived[]="jinan";
i++;
flight[i].flightnumber=5252;
flight[i].starttime=2120;
flight[i].arrivedtime=2355;
flight[i].start[]="guangzhou";
flight[i].arrived[]="taiyuan";
i++;
flight[i].flightnumber=3101;
flight[i].starttime=0825;
flight[i].arrivedtime=1055;
flight[i].start[]="guangzhou";
flight[i].arrived[]="beijing";
i++;
flight[i].flightnumber=6342;
flight[i].starttime=1450;
flight[i].arrivedtime=2010;
flight[i].start[]="guangzhou";
flight[i].arrived[]="changchun";
i++;
flight[i].flightnumber=6411;
flight[i].starttime=1100;
flight[i].arrivedtime=1240;
flight[i].start[]="zhengzhou";
flight[i].arrived[]="chengdu";
i++;
flight[i].flightnumber=8731;
flight[i].starttime=1655;
flight[i].arrivedtime=1905;
flight[i].start[]="chengdu";
flight[i].arrived[]="guangzhou";
i++;
flight[i].flightnumber=4203;
flight[i].starttime=1035;
flight[i].arrivedtime=1135;
flight[i].start[]="chengdu";
flight[i].arrived[]="xian";
i++;
flight[i].flightnumber=2284;
flight[i].starttime=1540;
flight[i].arrivedtime=1800;
flight[i].start[]="chengdu";
flight[i].arrived[]="beijing";
i++;
flight[i].flightnumber=2626;
flight[i].starttime=2015;
flight[i].arrivedtime=2130;
flight[i].start[]="chengdu";
flight[i].arrived[]="changsha";
}
void displayinfo() //显示航班信息
{ cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
for(i=1;i<=20;i++)
{cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;
}
void mainmenu() //主菜单
{
int y;
cout<<" mainmenu\n"<<endl;
cout<<" ==============================================\n"<<endl;
cout<<" Please choose: (input the number)\n"<<endl;
cout<<" 1. Find by flightnumber\n"<<endl;
cout<<" 2. Find by starttime\n"<<endl;
cout<<" 3. Find by arrivedtime\n"<<endl;
cout<<" 4. Find by start\n"<<endl;
cout<<" 5. Find by arrived\n"<<endl;
cout<<" 6. Sort by flightnumber\n"<<endl;
cout<<" 7. Sort by starttime\n"<<endl;
cout<<" 8. Sort by arrivedtime\n"<<endl;
cout<<" ==============================================\n"<<endl;
switch(y)
case 1:void findbyflightnum();break;
case 2:void findbystarttime();break;
case 3:void findbyarrivedtime();break;
case 4:void findbystart();break;
case 5:void findbyarrived();break;
case 6:void sortbyflightnum();break;
case 7:void sortbystarttime();break;
case 8:void sortbyarrivedtime();break;
default :cout<<"The number is error!"<<endl;mainmenu();
}
void findbyflightnum() //通过航班号查询
{
int a,x,i;
i=1;
cout<<"intput the flightnumber you want to find:"<<endl;
cin>>a;
while(a!=flight[i].flightnumber)&&(i<=20)
{
i++;
}
if(a==flight[i].flightnumber)
{
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;
}
else
cout<<"There is not any information about this flight!"<<endl;
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();
}
void findbystarttime() //通过起飞时间查询
{
int b,i,x;
i=1;
cout<<"intput the starttime you want to find(eg: 16:45 show as 1645):"<<endl;
cin>>b;
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
for(i=1;i<=20;i++)
{
if(b==flight[i].starttime)
cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;
}
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();}
void findbyarrivedtime() //通过到达时间查询
{
int c,i,x; i=1;
cout<<"Input the arrivedtime you want to find(eg: 16:45 show as 1645):"<<endl;
cin>>c;
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
for(i=1;i<=20;i++)
{
if(c==flight[i].arrivedtime)
cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;}
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();
}
void findbystart() //通过起点站查询
{
int i;
int j;
int x;
char st[10];
cout<<"Input the start you want to find:";
cin>>st;
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
for(i=1;i<=20;i++)
{if (strcmp(st,flight[i].start)==0)
cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;
}
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();}
void findbyarrived() //通过到达站查询
{
int i;
int j;
int x;
char at[10];
cout<<"Input the arrived you want to find:";
cin>>at;
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;
cout<<" flightnum starttime arrivedtime start arrived\n"<<endl;
for(i=1;i<=20;i++)
{if (strcmp(at,flight[i].start)==0)
cout<<" "<<flight[i].flightnumber<<" "<<flight[i].starttime<<"
"<<flight[i].arrivedtime<<" "<<flight[i].start[]<<" "<<flight
[i].arrived[]<<endl;
}
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();
}
void sortbyflightnum() //按航班号排序
{int i,j,k,b,x;
for(i=1.i<=20;i++)
{
k=i;
for(j=i+1;j<=20;j++)
{
if(flight[j].flightnumber<flight[k].flightnumber)
{k=j;}
}
if(k!=i)
{b=flight[i];flight[i]=flight[k];flight[k]=b;}
}
void displayinfo();
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();}
void sortbystarttime() //按起飞时间排序
{int i,j,k,b,x;
for(i=1.i<=20;i++)
{
k=i;
for(j=i+1;j<=20;j++)
{
if(flight[j].starttime<flight[k].starttime)
{k=j;}
}
if(k!=i)
{b=flight[i];flight[i]=flight[k];flight[k]=b;}
}
void displayinfo();
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();}
void sortbyarrivedtime() //按到达时间排序
{int i,j,k,b,x;
for(i=1.i<=20;i++)
{
k=i;
for(j=i+1;j<=20;j++)
{
if(flight[j].arrivedtime<flight[k].arrivedtime)
{k=j;}
}
if(k!=i)
{b=flight[i];flight[i]=flight[k];flight[k]=b;}
}
void displayinfo();
cout<<"If you want to return to main menu,please input 1:"<<endl;
cin>>x;
if(x==1)
void main();}
void main()
{
void flightinfo();
void displayinfo();
void mainmenu();
}
[此贴子已经被作者于2006-8-10 9:24:50编辑过]