如何使用String!恳求~(看看我的代码)
最近要写个作业,《航空客运订票系统》,现在暂时的想法是给没个终点站分配一条航线,每条航线的座位(有不同级别仓位)作为一条链表,然后客户预订机票后在相应的座位节点记录下信息,作为对应客户信息的下标!下面是暂时的代码!主要问题是使用String类,为什么在私有中定义了string,在flight的构造函数的初始化中还要在前面加是string才不会报错(使用VC8.0),而且运行查询航线,相应的终点名,航空号,飞机号都无法显示出来!望各位大侠指教!#include "iostream"
#include "string"
using namespace std;
class flight
{
public:
flight()
{
string endPoint[] = {"beijing","上海","杭州","南京","南宁","武汉","南昌","夏门","安徽","长沙"};
string planeNum[] = {"SCUT01","SCUT02","SCUT03","SCUT04","SCUT05","SCUT06","SCUT07","SCUT08","SCUT09","SCUT10"};
string flightNum[] = {"CZ01","CZ02","CZ03","CZ04","CZ05","CZ06","CZ07","CZ08","CZ09","CZ10"};
string flightDate[] = {"2008-6-25","2008-6-25","2008-6-26","2008-6-25","2008-6-25","2008-6-25","2008-6-25","2008-6-25","2008-6-25","2008-6-25"};
ration = 200;
int balance[] = {200,200,200,200,200,200,200,200,200,200};
}
~flight() {}
void checkAll();
void checkLane();
bool book(){return true;}
bool returnTicket(){return true;}
bool imformation(){return true;}
private:
string endPoint[10];
string planeNum[10];
string flightNum[10];
string flightDate[10];
int ration;
int balance[10];
};
//查看所有航班
void flight::checkAll()
{
cout<<"终点站 航班号 飞机号 飞行日期 乘员定额 余票量"<<endl;
for (int i = 0; i < 10; i++)
{
cout<<endPoint[i]<<" "<<flightNum[i]<<" "<<planeNum[i]<<" "<<flightDate[i]<<" "<<ration<<" "<<balance[i]<<endl;
}
}
//查询航线
void flight::checkLane()
{
string endP;
bool check = false;
cout<<"输入你所要到达的终点站:\n(暂提供北京、上海、杭州、南京、南宁、武汉、南昌、夏门、安徽、长沙的航班)"<<endl;
cin>>endP;
for (int i = 0; i < 10; i++)
{
if (endP == endPoint[i])
{
cout<<"终点站 航班号 飞机号 飞行日期 余票量\n"
<<endPoint[i]<<" "<<flightNum[i]<<" "<<planeNum[i]<<" "<<flightDate[i]<<" "<<balance[i]<<endl;
check = true;
}
}
if (check == false)
{
cout<<"没有达到该地点的航班!"<<endl;
}
}
void main()
{
char choice;
flight Flight;
do
{
cout<<"\n\n***************************航空客运订票系统***************************\n"
<<"***** *****\n"
<<"—————————————选择所要进行的操作—————————————\n"
<<" 1.查看所有航班 \n"
<<" 2.查询航线 \n"
<<" 3.订购机票 \n"
<<" 4.退订机票 \n"
<<" 5.查看自己订票信息 \n"
<<" 0.退出系统 \n"
<<"输入你的选择: ";
cin>>choice;
if (choice != '0')
switch(choice)
{
case '1' : Flight.checkAll();break;
case '2' : Flight.checkLane();break;
case '3' : Flight.book();break;
case '4' : Flight.returnTicket();break;
case '5' : Flight.imformation();break;
default : break;
}
}while(choice != '0');
cout<<"————已退出系统! ";
}
[[it] 本帖最后由 gavinming 于 2008-6-15 18:56 编辑 [/it]]