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

我们的课程设计题目,要求能够对航班信息进行排序和查询,按航班号,起点站,到达站,起飞时间,到达时间查询。
我用的是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
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

如果只是排序,查询,当然是用顺序储存了,速度快,那个结构体的内容就是 航班号,起点站,到达站,起飞时间,到达时间就可以了反正你数组的每一个元素是一个结构体就可以了.这个题目论坛好像以前有人做过,你搜索一下本板块


c++/C + 汇编 = 天下无敌
2006-08-08 13:15
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
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
HB *Airplane = (HB*)malloc( N *sizeof(HB));


c++/C + 汇编 = 天下无敌
2006-08-09 00:06
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 
DDDDDDDDDDD,高手们帮我看看吧

2006-08-10 09:30
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

惨罗,出现很多重复的语句。。。。。。那个询问信息的,你完全可以做一个函数输出那些信息
例如
cout<<" ****************************************\n"<<endl;
cout<<" * flight informations *\n"<<endl;
cout<<" ****************************************\n"<<endl;

还有,你应该将航班的信息促存在文本,程序启动的时候你可以从文本读信息
另外如果你想连接数据库,那你要去学VC++了。


c++/C + 汇编 = 天下无敌
2006-08-10 20:10
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

另外我以前写了个图书管理系统,你可以参考一下,就是程序启动的时候会读文件的

//标准C++定义头文件方法
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <memory>
#include <ctime>


using namespace std;

namespace LIBARAY
{
class BOOK
{
public:
BOOK(){}
~BOOK();

string m_bName; //图书名称
string m_publishofBook; //图书出版社
float m_bPrice; //图书价钱
unsigned short m_bNum; //图书库存量
unsigned short m_bnowNum; //图书现有数量
static map<int, BOOK* ,less<int> ,
allocator<pair<int,BOOK*> > > m_bMap;
static map<int, BOOK* ,less<int> ,
allocator<pair<int,BOOK*> > >::iterator pos;
//图书储存机制
// 第一个参数是记录图书ID
};
map<int, BOOK* ,less<int> ,
allocator<pair<int,BOOK*> > > BOOK::m_bMap;
map<int, BOOK* ,less<int> ,
allocator<pair<int,BOOK*> > >::iterator BOOK::pos;

BOOK::~BOOK()
{
for(BOOK::pos = BOOK::m_bMap.begin (); BOOK::pos != BOOK::m_bMap.end(); BOOK::pos++)
{
delete pos->second;
pos->second = NULL;
}
}

class PERSON
{
public:
PERSON(){}
~PERSON();
//借书日期
char m_brrowDate[30];
//还书的日期
char m_returnDate[30];
unsigned short m_bookNumber ; //所借的图书的数量
string m_readName; //读者姓名
unsigned int m_rebonum; //已借书的编号

static map<int, PERSON* ,less<int> ,
allocator<pair<int,PERSON*> > > m_pMap;
static map<int, PERSON* ,less<int> ,
allocator<pair<int,PERSON*> > >::iterator pos;
//个人储存机制
//第一个参数是记录读者ID
};
map<int, PERSON* ,less<int> ,
allocator<pair<int,PERSON*> > > PERSON::m_pMap;
map<int, PERSON* ,less<int> ,
allocator<pair<int,PERSON*> > >::iterator PERSON::pos;

PERSON::~PERSON()
{
for(PERSON::pos = PERSON::m_pMap.begin (); PERSON::pos != PERSON::m_pMap.end(); PERSON::pos++)
{
delete pos->second;
pos->second = NULL;
}
}

class LIBARAYOPERATOR
{
public:
static void ReadFile(); //读文件
static void WriteFile(); //写文件
static void AddNewBook(); //新书入库
static void BrrowBook(); //借书
static void ReturnBook(); //还书
static void AddReader(); //读者管理
static void DisplayBook(); //输出图书资料
static void DisplayReader(); //输出读者资料
};

void LIBARAYOPERATOR::ReadFile ()
{
ifstream readFile("Book.txt", ios_base::in);
if(!readFile)
{
cout << "不能打开文件!" <<endl;
exit(1);
}

ifstream readPersonFile("Person.txt",ios_base::in);
if(!readPersonFile)
{
cout << "不能打开文件!" <<endl;
exit(1);
}

string textline;
string textlineForPerson;
string temp;
int index = 0;

string::size_type position_start = 0;
string::size_type position_end = 0;

while(getline(readFile,textline,'\n'))
{

BOOK *pbook = new BOOK;
position_start = 0;
position_end = 0;
index = 0;

while( (position_end = textline.find_first_of('\t',position_start)) != string::npos)
{
temp = textline.substr(position_start,position_end - position_start);
switch(index)
{
case 0:
pbook->m_bName = temp;
break;
case 1:
pbook->m_publishofBook = temp;
break;
case 2:
{
char bufferPrice[10];
memset(bufferPrice,0,sizeof(bufferPrice));
strcpy(bufferPrice,temp.c_str());
pbook->m_bPrice = atof(bufferPrice);
break;
}
case 3:
{
char bufferNum[10];
memset(bufferNum,0,sizeof(bufferNum));
strcpy(bufferNum,temp.c_str());
pbook->m_bNum = atoi(bufferNum);
break;
}
case 4:
{
char bufferNowNum[10];
memset(bufferNowNum,0,sizeof(bufferNowNum));
strcpy(bufferNowNum,temp.c_str());
pbook->m_bnowNum = atoi(bufferNowNum);
break;
}
}

index ++;
position_start = ++position_end;
}
temp = textline.substr(position_start,position_end - position_start);
char bufferbookID[10];
memset(bufferbookID,0,sizeof(bufferbookID));
strcpy(bufferbookID,temp.c_str());
unsigned int BookID = atoi(bufferbookID);

BOOK::m_bMap.insert(make_pair(BookID, pbook));
}

readFile.close();

index = 0;

while(getline(readPersonFile,textlineForPerson,'\n'))
{
position_start = 0;
position_end = 0;
index = 0;
PERSON *pPerson = new PERSON;

while( (position_end = textlineForPerson.find_first_of('\t',position_start)) != string::npos)
{
temp = textlineForPerson.substr(position_start,position_end - position_start);
switch(index)
{
case 0:
pPerson->m_readName = temp;
break;
case 1:
{
char bufferBookofBrrow[10];
memset(bufferBookofBrrow,0,sizeof(bufferBookofBrrow));
strcpy(bufferBookofBrrow,temp.c_str());
pPerson->m_rebonum = atoi(bufferBookofBrrow);
break;
}
case 2:
{
char bufferNumofBrrowbook[10];
memset(bufferNumofBrrowbook,0,sizeof(bufferNumofBrrowbook));
strcpy(bufferNumofBrrowbook,temp.c_str());
pPerson->m_bookNumber = atoi(bufferNumofBrrowbook);
break;
}
case 3:
{
strcpy(pPerson->m_brrowDate ,temp.c_str());
break;
}
case 4:
{
strcpy(pPerson->m_returnDate ,temp.c_str());
break;
}
}

index ++;
position_start = ++position_end;
}
temp = textlineForPerson.substr(position_start,position_end - position_start);
char bufferReadID[10];
memset(bufferReadID,0,sizeof(bufferReadID));
strcpy(bufferReadID,temp.c_str());
unsigned int ReaderID = atoi(bufferReadID);
PERSON::m_pMap.insert(make_pair(ReaderID, pPerson));
}
}

void LIBARAYOPERATOR::WriteFile()
{
ofstream outfileBook("Book.txt", ios_base::out | ios_base::trunc);

for(BOOK::pos = BOOK::m_bMap.begin (); BOOK::pos != BOOK::m_bMap.end(); BOOK::pos++)
{
outfileBook << BOOK::pos->second->m_bName << '\t' << BOOK::pos->second->m_publishofBook << '\t'
<< BOOK::pos->second->m_bPrice<<'\t'<< BOOK::pos->second->m_bNum<<'\t'
<<BOOK::pos->second->m_bnowNum<<'\t'<<BOOK::pos->first<<endl;
}

outfileBook.close();

ofstream outfilePerson("Person.txt",ios_base::out | ios_base::trunc);

for(PERSON::pos = PERSON::m_pMap.begin(); PERSON::pos != PERSON::m_pMap.end(); PERSON::pos++)
{
outfilePerson <<PERSON::pos->second->m_readName <<'\t'<<PERSON::pos->second->m_rebonum <<'\t'
<< PERSON::pos->second->m_bookNumber <<'\t'<<PERSON::pos->second->m_brrowDate << '\t'
<<PERSON::pos->second->m_returnDate <<'\t'<<PERSON::pos->first<<endl;
}

outfilePerson.close();

}

void LIBARAYOPERATOR::DisplayBook()
{
cout << "图书资料:" <<endl;
cout <<"图书编号"<<" "<<"图书名称"<<" "<<"图书出版社"<<" "<<"图书数量"<<" "<<"图书现存量"<<endl;

for(BOOK::pos = BOOK::m_bMap.begin (); BOOK::pos != BOOK::m_bMap.end(); BOOK::pos++)
{
cout << BOOK::pos->first<< " " << BOOK::pos->second->m_bName << " "
<< BOOK::pos->second->m_publishofBook << " "<< BOOK::pos->second->m_bPrice<<" "
<< BOOK::pos->second->m_bNum<< " " <<BOOK::pos->second->m_bnowNum<<endl;
}
cout << endl;
}

void LIBARAYOPERATOR::DisplayReader()
{
cout << "读者资料:" <<endl;
cout << "读者编号"<<" "<<"读者名称"<<" "<<"已借书编号"<<" "<<"所借书的数量"<<" "<<"借书日期"<<" "<<"还书日期"<<endl;
for(PERSON::pos = PERSON::m_pMap.begin(); PERSON::pos != PERSON::m_pMap.end(); PERSON::pos++)
{
cout <<PERSON::pos->first<< " " <<PERSON::pos->second->m_readName << " "
<<PERSON::pos->second->m_rebonum << " " << PERSON::pos->second->m_bookNumber << " "
<<PERSON::pos->second->m_brrowDate << " " <<PERSON::pos->second->m_returnDate <<endl;
}
cout << endl;
}

void LIBARAYOPERATOR::AddNewBook()
{
LIBARAY::LIBARAYOPERATOR::DisplayBook();
BOOK *pBook = new BOOK;
unsigned int BookID;

cout << "请输入图书编号:(数字)" <<endl;
cin >> BookID;
fflush(stdin);

BOOK::pos = BOOK::m_bMap.find(BookID);
if( BOOK::pos != BOOK::m_bMap.end())
{
cout << "该图书已经存在!"<<endl;
return;
}

cout << "请输入图书名称:" <<endl;
getline(cin,pBook->m_bName,'\n');
cout << "请输入图书的出版社:" <<endl;
getline(cin,pBook->m_publishofBook,'\n');
cout << "请输入图书的价钱:" <<endl;
cin >> pBook->m_bPrice;
cout << "请输入录入的图书数目:" <<endl;
cin >> pBook->m_bNum;

pBook->m_bnowNum = pBook->m_bNum;
BOOK::m_bMap.insert (make_pair(BookID, pBook));

}

void LIBARAYOPERATOR::AddReader()
{
LIBARAY::LIBARAYOPERATOR::DisplayReader();

PERSON *pPerson = new PERSON;
unsigned int ReaderID;

cout << "请输入学号(有意义的数字):" <<endl;
cin >> ReaderID;
fflush(stdin);



c++/C + 汇编 = 天下无敌
2006-08-10 20:15
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 

PERSON::pos = PERSON::m_pMap.find(ReaderID);

if(PERSON::pos != PERSON::m_pMap.end())
{
cout << "该ID已有人使用: " << endl;
return;
}

cout << "请输入姓名:" << endl;
getline(cin, pPerson->m_readName, '\n');

pPerson->m_bookNumber = 0;
memset(pPerson->m_brrowDate,0, sizeof(pPerson->m_brrowDate));
pPerson->m_rebonum = 0;
memset(pPerson->m_returnDate,0,sizeof(pPerson->m_returnDate));

PERSON::m_pMap.insert (make_pair(ReaderID,pPerson));
}

void LIBARAYOPERATOR::BrrowBook()
{
LIBARAY::LIBARAYOPERATOR::DisplayBook();
unsigned int BookID, ReaderID;

cout << "请输入个人编号: " << endl;
cin >> ReaderID;

PERSON::pos = PERSON::m_pMap.find (ReaderID);

if(PERSON::pos == PERSON::m_pMap.end())
{
cout << "该ID不存在!" << endl;
return;
}

if(PERSON::pos->second->m_brrowDate != "" && PERSON::pos->second->m_brrowDate == "")
{
cout << "该读者已经借了图书阅读!"<<endl;
return;
}

cout << "请输入要借的书的编号:" << endl;
cin >> BookID;

BOOK::pos = BOOK::m_bMap.find(BookID);

if(BOOK::pos == BOOK::m_bMap.end())
{
cout << "该图书不存在!" << endl;
return;
}

if(BOOK::pos->second->m_bnowNum == 0)
{
cout <<"该图书已经被借完!"<<endl;
return;
}

BOOK::pos->second->m_bnowNum--;
PERSON::pos->second->m_bookNumber= 1;
PERSON::pos->second->m_rebonum = BookID;

struct tm *newtime;
time_t now;
time(&now);
newtime = localtime(&now);

strftime(PERSON::pos->second->m_brrowDate, sizeof(PERSON::pos->second->m_brrowDate),"%Y/%m/%d",newtime);
}

void LIBARAYOPERATOR::ReturnBook()
{
LIBARAY::LIBARAYOPERATOR::DisplayReader();
unsigned int ReaderID;
cout << "请输入个人编号: " << endl;
cin >> ReaderID;

PERSON::pos = PERSON::m_pMap.find (ReaderID);

if(PERSON::pos == PERSON::m_pMap.end())
{
cout << "该ID不存在!" << endl;
return;
}

BOOK::pos = BOOK::m_bMap.find(PERSON::pos->second->m_rebonum);

BOOK::pos->second->m_bnowNum += PERSON::pos->second->m_bookNumber;
PERSON::pos->second->m_bookNumber = 0;
PERSON::pos->second->m_rebonum = 0;

struct tm *newtime;
time_t now;
time(&now);
newtime = localtime(&now);

strftime(PERSON::pos->second->m_returnDate, sizeof(PERSON::pos->second->m_returnDate),"%Y/%m/%d",newtime);

}
}

void Enterchoice(int ch)
{
//reader p;
if(ch < 0||ch > 5){
cout<<"输入错误!\n请重新输入!"<<endl;
return;
}

switch(ch)
{
case 1:
LIBARAY::LIBARAYOPERATOR::AddNewBook();
break;
case 2:
LIBARAY::LIBARAYOPERATOR::DisplayBook();
LIBARAY::LIBARAYOPERATOR::DisplayReader();
break;
case 3:
LIBARAY::LIBARAYOPERATOR::ReturnBook();
break;
case 4:
LIBARAY::LIBARAYOPERATOR::BrrowBook();
break;
case 5:
LIBARAY::LIBARAYOPERATOR::AddReader();
break;
}

}

int main()
{
LIBARAY::LIBARAYOPERATOR::ReadFile ();
int choice ;
do{
cout <<"\n\n\n\n";
cout <<"\t\t 图书管理系统 \n";
cout <<"\t\t 主菜单      \n";
cout <<"\t\t\t @@@@@@@@@@@@@@@@@@@";
cout <<"\n\n\n";
cout <<"\t\t 1. 新书入库 \n";
cout <<"\t\t 2. 资料输出 \n";
cout <<"\t\t 3.还书    \n";
cout <<"\t\t 4.借书    \n";
cout <<"\t\t 5.读者管理 \n";
cout <<"\t\t 0.退出系统 \n";
cout <<"\n\n\n\n";
cout <<"请输入你要进行的操作:\n";
cin>>choice;
Enterchoice(choice);
}while(choice!=0);
cout << "谢谢光临本系统!!!"<<endl;
LIBARAY::LIBARAYOPERATOR::WriteFile();
return 0;
}


c++/C + 汇编 = 天下无敌
2006-08-10 20:15
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
另外你用我的程序之前要 建立两个文本文件 一个是 Book.txt,一个是 Person.txt

反正跟你那个航班的差不多,你可以依照我的框架去改
如果不会用map 跟迭代器(iterator)就先去找本C++教程看看,这里只负责数据结构

c++/C + 汇编 = 天下无敌
2006-08-10 20:18
cky1014
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2006-8-8
收藏
得分:0 

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


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



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

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