| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2808 人关注过本帖
标题:[求助]航班信息的查询和检索(加了我编的程序,但错误好多)
取消只看楼主 加入收藏
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
 问题点数:0 回复次数:5 
[求助]航班信息的查询和检索(加了我编的程序,但错误好多)

我们的课程设计题目,要求能够对航班信息进行排序和查询,按航班号,起点站,到达站,起飞时间,到达时间查询。
我用的是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编辑过]

搜索更多相关主题的帖子: 航班信息 链式 检索 
2006-08-08 10:47
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 

链式存储的话结构体我知道定义,就是比如说
typedef struct HB{
int time;
int number;
……(省略)
struct HB *next;
}HB,*list;
就是要有一个指针,调用时p->next阿,p->time阿,就行了,那顺序存储呢?我就是不会结构体定义,能写个出来看看么?是要用数组把,那调用呢?


2006-08-08 23:15
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 
DDDDDDDDDDD,高手们帮我看看吧

2006-08-10 09:30
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 

重复语句的问题应该是优化的问题,我想起码程序能运行了再去优化,还有我们是数据结构的课程设计,老师主要看检索的部分,就想偷个懒直接把信息这样写。加上本身C++学得不多,连模版都没学到,所以热情依然GG写的程序我都不太看得懂,更不用说仿着写一个新的了,所以想让你帮看看我的程序到底是哪里出了差错不能运行,是不是有致命的错误,是不是非得重新推翻重写不可,我是菜鸟,所以比较麻烦,谢谢帮忙。如果方便,加我qq聊,87611737,谢谢


2006-08-15 17:15
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 
还有还有,热情依然GG那个Book.txt和Person.txt两个文件建立以后保存在什么位置?这两个文件里的格式是怎么样的?不可能是随便写吧?

2006-08-15 17:21
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 
对不起,还有问题,那个我加了那两个文件了,里面什么都没写,空的。然后运行程序,能运行,但是我选择了新书入库,输入图书编号和书名都没问题(有点小问题是书名要打两次回车才能继续运行)但是输入出版社名称时,一打回车那个黑色的匡阿,就在不停的滚动字,大概就是图书管理系统的那个主菜单,滚个不停,只能把黑色的匡关掉才行,是我电脑的问题么?还是怎么回事?
还有还有,我怎么能让程序一开始就有资料,是在两个txt文件里编辑么?格式呢?不好意思,菜鸟的问题是比较多的

2006-08-15 17:41
快速回复:[求助]航班信息的查询和检索(加了我编的程序,但错误好多)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038511 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved