这个怎么有几个不知道什么错误
找了很久
#include<iostream>
#include<cstdlib>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
# define MAX 5
class Flight//航班信息类
{
friend class Customer;
private:
char FlyCode[6];//航班号
char Start[15];//起始站
char End[15];//终点站
char Time[10];//飞行时间(星期几)
int SumNum;//成员定额数量
int AvailNum;//未售出数量
char choice;//存放任意字符
public:
Flight();//构造函数
void Interface();//界面
void Show();//输出信息
void SwitchChoice();//选择命令
void AddFly();//添加新的航班信息
};
Flight fly[MAX],temp;
class Customer//顾客类
{
private:
char UserName[20];//用户名
char PassWord[10];//用户密码
char TicketCode[6];//拥有机票的航班号
char anychar;//存放任意字符
int HoldNum;//拥有机票数量
public:
Customer();//构造函数
void Login(char*,Customer) const ;//用户登陆
void Register(Customer *);//用户开户
void Business(Customer ) const; //业务办理操作
};
Customer::Customer()//默认构造,初始0
{
strcpy(Customer::UserName,"");
strcpy(Customer::TicketCode,"0");
Customer::HoldNum=0;
}
void Customer::Login(char*password,Customer user) const
{
ifstream read_user("user.dat");//读入文件
while(!read_user.eof())
{
read_user.read((char*)(&user),sizeof(user));
if(read_user.fail())
{
cout<<"No record at all.";
break;
}
if(strcmp(password,user.PassWord)==0)//验证密码
Business(user); //正确,进入业务办理系统
}
void Customer::Register(Customer*user)
{
system("cls");//系统命令:清屏
cin.get();
cout<<"\t\t^^^^^欢迎到航空售票业务办理系统^^^^^!"<<endl;
cout<<"......................................................"<<endl;
cout<<"请输入您的用户名:";
cin.getline(UserName,30);
cout<<"请输入您的用户密码:(少于8个字符)";
cin>>Password;
cin.get();
system("cls");
cout<<endl<<endl;
cout<<"您的帐户已经被建立,可以开始进入业务办理系统...";
cout<<"按任意键开始...... ";
//cin.getch();
cin>>anychar;//getch()
}
//业务办理操作
void Customer::Business(Customer user)const
{
Flight forbuy[MAX],temp;
Customer nc[MAX];
int i;
char c,anychar, BuyCode[6];
int BuyNum;
start:
system("cls");
cout<<endl<<endl;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<"\t\t\t__ _ _ __欢迎返回!_______";
cout<<" \t\t_ _ _ _ 航空售票业务办理系统_ _ _";
cout<<" ";
cout<<"\t\t当前用户:"<<user.UserName<<endl<<endl;
cout<<"\t\t[b]-------购票 [s]---------退票 ";
cout<<"\t\t[l]-------用户信息 [q]---------退出 "<<endl;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
cout<<"请输入您的选择:";
cin>>ch;
if((ch!='b')&&(ch!='s')&&(ch!='l')&&(ch!='q'))
{
cout<<"输入错误,请您重新输入:";
goto start;
}
else
{
switch(ch)
//购票
case'b':
system("cls");
cout<<"\n\n\t\t$$$---购票交易系统---$$$";
cout<<"航班号\t\t起始站\t终点站\t飞行时间\t成员定额\t空位数目"<<endl;
//输入机场航班文件
ifstream fly("fly.dat");//输入航班信息
fly.read((char*)(&forbuy),sizeof(forbuy));//航班信息读入forbuy
ifsream myrecord(user.UserName); //用户目前资料
myrecord.read((char*)(&nc),sizeof(nc));//将用户目前的资料读入内存
for(i=0;i=<MAX;++i)
forbuy[i].Show();//显示航班信息
cin.get();
cout<<endl<<"请输入您购买的航班号:";
cin.getline(BuyCode,6);
cout<<"输入您购买的数量:";
cin>>BuyNum;
cin.get();
i=0;
while((strcmp(forbuy[i].FlyCode,BuyCode)==0)||(i<MAX))
{
if((strcmp(forbuy[i].FlyCode,BuyCode)==0)//输入了正确的航班号
{
if(forbuy[i].AvailNum>BuyNum)//满足要求的数量
{
nc[i].HoldNum=nc[i].HoldNum+BuyNum;//添加拥有的机票数目
strcpy(nc[i].FlyCode,forbuy[i].TicketCode);
forbuy[i].AvailNum=forbuy[i].AvailNum-BuyNum;//机场航班数量相应减少
ofstream fly(user.UserName,ios::binary);
for(i=0;i<5;++i)
fly.write((char*)(&nc[i]),sizeof(nc[i]));
ofstream file("fly.dat");//将交易结果保存在航班信息文件
for(i=0;i<5;++i)
file.write((char*)(&forbuy[i]),sizeof(forbuy[i]));
break;
}
else
{
cout<<forbuy[i].TicketCode<<"的数目不足。"<<endl;
cout<<"不能购买此次航班的机票....";
cin>>anychar;
break;
}
}
else
{
i++;
while(i==MAX)
{
cout<<"航班代码错误...";
cout<<"购买无效"
cin>>anychar;
break;
}
}
}
break;
}
case's':
{
system("cls");
ifstream forbuy(user.UserName);
forbuy.read((char*)(&nc),sizeof(nc));
ifstream fly("fly.dat");
forbuy.read((char*)(&forbuy),sizeof(forbuy));
cout<<"\t\t$$$---购票交易系统---$$"<<endl;
cout<<"航班号\t\t\t拥有数目"<<endl;
//输入机场航班文件
for(int i=0;i<MAX;i++)
cout<<" "<<nc[i].TicketCode<<"\t\t\t"<<nc[i].HoldNum<<endl;
cin.get();
cout<<endl<<"输入您退的机票航班号:";
cin.getline(BuyCode,6);
cout<<"输入您退票的数目:";
cin>>BuyNum;
cin.get();
i=0;
while((strcmp(forbuy[i].FlyCode,BuyCode)==0)||(i<MAX))
{
if(strcmp(forbuy[i].FlyCode,BuyCode)==0)
{
if(nc[i].AvailNum>BuyNum)
{
nc[i].HoldNum=nc[i].HoldNum-BuyNum;
forbuy[i].AvailNum=forbuy[i].AvailNum+BuyNum;
ofstream data(user.UserName,ios::binary);
for(i=0;i<5;++i)
data.write((char*)(&nc[i]),sizeof(nc[i]));
ofstream file("fly.dat");
for(i=0;i<5;++i)
file.write((char*)(&forbuy[i]),sizeof(forbuy[i]));
}
else
{
cout<<"您没有那么多数量的机票或者航班号有误\n";
cout<<"退票失败...\n";
break;
}
}
else
{
i++;
while(i==MAX)
cout<<"您没有此航班机票\n 交易取消...";
break;
}
}
}
//getch()
cin>>anychar;
break;
case'v':
{
system("cls");
ifstream forbuy(user.UserName);
cout<<"\t\t$$$---个人购票信息---$$"<<endl;
cout<<"航班号\t\t\t拥有数目"<<endl;
//输入机场航班文件
for(int i=0;i<MAX;i++)
cout<<" "<<nc[i].TicketCode<<"\t\t\t"<<nc[i].HoldNum<<endl;
//getch();
cin>>anychar;
break;
}
case'q':
{
temp.Interface();
}
goto start;
}
}
Flight::Flight()
{
AvailNum=SumNum;
}
void Flight::Interface()
{
start:
system("cls");
cout<<"\n\n\t\t^^^^^^^^^^^欢迎到航空售票业务办理系统^^^^^^^^^^"<<endl;
cout<<"\t\t__ ___";
cout<<"\t\t[m]----查看航班信息 [i]----用户登陆 ";
cout<<"\t\t[r]----注册新的用户 [q]----退出系统"<<endl<<endl;
cout<<"\t\t请输入您的选择:";
cin>>choice;
if((choice!='m')&&(choice!='i')&&(choice!='r')&&(choice!='q'))
{
system("cls");
goto start;
}
else
SwitchChoice();
}
void Flight::SwitchChoice()
{
Customer us;
Flight nc[MAX];
char anychar,Password[10];
switch(choice)
{
//查看航班信息
case'm':
{
system("cls");
cout<<"__ __ __ __ __ __当前航班信息__ __ __ __ __ __"<<endl;
cout<<"航班号\t\t起始站\t终点站\t飞行时间\t成员定额\t空位数目"<<endl;
//打开航班文件
ifstream fly("fly.dat");
fly.read((char*)(&nc),sizeof(nc));
for(int x=0;x<5;++x)
nc[x].Show();
//getch()
cin>>anychar;
fly.close();
temp.Interface();
break;
}
//用户登陆
case'i':
{
system("cls");
cout<<"航空售票业务办理系统"<<endl;
cout<<"用户密码:";
cin>>Password;
cin.get();
us.Login(Password,us);
temp.Interface();
break;
}
//用户注册
case'r':
{
system("cls");
cout<<"欢迎注册航空售票业务办理系统!"<<endl;
us.Register(&us);
//写入用户资料
ofstream inuser("user.dat",ios::app);
inuser.write((char*)(&us),sizeof(us));
inuser.close();
temp.Interface();
break;
}
case'q':
{
system("cls");
cout<<"感谢使用航空售票业务办理系统!"<<endl;
cout<<"再见!"<<endl;
//ofs
}
}
}
//增加新的航班数据
void Flight::AddFly()
{
system("cls");
cin.get();
cout<<"Enter new FlyCode:";
cin.getline(FlyCode,6);
cout<<"Enter Start:";
cin.getline(Start,15);
cout<<"Enter End:";
cin.getline(End,15);
cout<<"Enter Time";
cin.getline(Time,10);
cout<<"Enter SumNum:";
cin>>SumNum;
cin.get();
AvailNum=SumNum;
}
void Flight::Show()
{
cout<<" "<<FlyCode<<"\t\t"<<Start<<"\t"<<End<<"\t"<<Time<<"\t"<<SumNum<<"\t"<<AvailNum<<endl;
}
int main()
{
//第一次使用时将注释去掉
//新建系统,以后如不改动航班信息,则应加上注释
/*
const num=5;
ofstream fly("fly.dat");
for(int x=0;x<5;++x)
{
nc[x].AddFly();
fly.write((char*)(&nc[x],sizeof(nc[x]));
}
fly.close();
*/
temp.Interface();
return 0;
}