📄 xiao123.c
字号:
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<windows.h>
class daytime
{
public:
int weekday;
int hour;
int minute;
daytime()
{
weekday=hour=minute=0;
}
~daytime()
{}
};
class samepart
{
public:
char begcity[20]; // 起点城市
char arrivecity[20]; // 终点城市
char hangbancode[10]; // 航班编号
int flycode; // 飞机号
daytime lefttime; // 起飞时间
daytime arrivetime; // 到达时间
samepart()
{
strcpy(begcity,"");
strcpy(arrivecity,"");
strcpy(hangbancode,"");
strcpy(hangbancode,"");
flycode=0;
}
~samepart()
{}
};
class seat
{
public:
int chars;
double price;
int leftseat;
int position; // 座位号
seat()
{
chars=leftseat=position=0;
price=0;
}
~seat()
{}
};
class guestmessage:public samepart
{
public:
int sum;
long ID; // 证件号
int linedata; // 订票编号
char name[20];
int total; // 订票总数
int dengji;
int seats[10];
guestmessage *next;
guestmessage()
{
for(int i=0;i<10;i++)
seats[i]=0;
ID=linedata=0;
strcpy(name,"");
};
~guestmessage()
{
};
};
class blackseat
{
public:
int counter;
char hangbancode[10];
int flycode;
int chars;
int position;
blackseat *next;
blackseat()
{
strcpy(hangbancode,"");
flycode=0;
chars=0;
position=0;
counter=0;
}
};
struct operater // 机场工作人员姓名与工作密码
{
char code[20];
char name[20];
};
class flymessage:public samepart
{
public:
int counter;
int maxseat; // 最大容量
double count; // 打折数
seat seats[4];
bool empty; // 是否满舱
int didbook; // 已经订票人数
flymessage *next;
flymessage()
{
maxseat=didbook=0;
empty=false;
count=0.0;
};
~flymessage()
{};
};
istream & operator>>(istream &in,flymessage &flymess) //重载运算符>>
{
in>>flymess.hangbancode;
in>>flymess.flycode;
in>>flymess.begcity;
in>>flymess.arrivecity;
in>>flymess.count;
in>>flymess.didbook;
in>>flymess.maxseat;
in>>flymess.lefttime.weekday;
in>>flymess.lefttime.hour;
in>>flymess.lefttime.minute;
in>>flymess.arrivetime.weekday;
in>>flymess.arrivetime.hour;
in>>flymess.arrivetime.minute;
for(int i=1;i<4;i++)
{
in>>flymess.seats[i].leftseat;
in>>flymess.seats[i].price;
}
return in;
}
ostream & operator <<(ostream &os,flymessage &flymess) //重载运算符<<
{
os<<flymess.hangbancode<<'\t';
os<<flymess.flycode<<'\t';
os<<flymess.begcity<<'\t';
os<<flymess.arrivecity<<'\t';
os<<flymess.count<<'\t';
os<<flymess.didbook<<'\t';
os<<flymess.maxseat<<'\t';
os<<flymess.lefttime.weekday<<" ";
os<<flymess.lefttime.hour<<" ";
os<<flymess.lefttime.minute<<" ";
os<<flymess.arrivetime.weekday<<" ";
os<<flymess.arrivetime.hour<<" ";
os<<flymess.arrivetime.minute<<'\t';
for(int i=1;i<4;i++)
{
os<<flymess.seats[i].leftseat<<" ";
os<<flymess.seats[i].price<<'\t';
}
os<<endl;
return os;
}
istream & operator >>(istream &in,guestmessage &guest) //重载运算符>>
{
in>>guest.hangbancode;
in>>guest.flycode;
in>>guest.begcity;
in>>guest.arrivecity;
in>>guest.lefttime.weekday;
in>>guest.lefttime.hour;
in>>guest.lefttime.minute;
in>>guest.arrivetime.weekday;
in>>guest.arrivetime.hour;
in>>guest.arrivetime.minute;
in>>guest.ID;
in>>guest.name;
in>>guest.linedata;
in>>guest.total;
in>>guest.dengji;
return in;
}
ostream & operator<<(ostream &os,guestmessage &guest) //重载运算符<<
{
os<<guest.hangbancode<<'\t';
os<<guest.flycode<<'\t';
os<<guest.begcity<<'\t';
os<<guest.arrivecity<<'\t';
os<<guest.lefttime.weekday<<" ";
os<<guest.lefttime.hour<<" ";
os<<guest.lefttime.minute<<'\t';
os<<guest.arrivetime.weekday<<" ";
os<<guest.arrivetime.hour<<" ";
os<<guest.arrivetime.minute<<'\t';
os<<guest.ID<<'\t';
os<<guest.name<<'\t';
os<<guest.linedata<<'\t';
os<<guest.total<<'\t';
os<<guest.dengji;
os<<endl;
return os;
}
istream & operator << (istream &in,blackseat &blackst)
{
in>>blackst.chars;
in>>blackst.hangbancode;
in>>blackst.flycode;
in>>blackst.position;
return in;
}
ostream & operator>>(ostream &os,blackseat &blackst)
{
os<<blackst.chars<<'\t';
os<<blackst.hangbancode<<'\t';
os<<blackst.flycode<<'\t';
os<<blackst.position<<endl;
return os;
}
//------------------------------------------------------------------------------------------
void inifiledata() // 初始化航班信息文件、查询索引表文件的数据
{
fstream datafile1,datafile2,datafile3,datafile4;
datafile1.open("航班的基本信息数据.dat",ios::out);
if(!datafile1)
cout<<"航班的基本信息数据.dat文件不存在!"<<endl;
else
datafile1<<0<<endl;
datafile1.close();
datafile2.open("客户信息库.dat",ios::out);
if(!datafile2)
cout<<"客户信息库.dat文件不存在!"<<endl;
else
datafile2<<0<<endl;
datafile2.close();
datafile3.open("已订票的客户座位信息.dat",ios::out);
if(!datafile3)
cout<<"已订票的客户座位信息文件不存在!"<<endl;
datafile3<<0<<endl;
datafile3.close();
datafile4.open("退票的位子信息.txt",ios::out);
if(!datafile4)
cout<<"退票后的空位文件不存在"<<endl;
else
datafile4<<0<<endl;
datafile4.close();
system("cls");
cout<<"所有数据文件已经初始化!"<<endl;
}
//-----------------------------------------------------------------------------------------
void savealldata(flymessage *hangban) //将工作人员所修改的数据保存
{
fstream hangbanfile;
flymessage *p;
p=hangban->next;
hangbanfile.open("航班的基本信息数据.dat",ios::out);
hangbanfile<<hangban->counter<<endl;
if(hangban->counter==1)
hangbanfile<<*hangban;
else
{
while(p!=NULL)
{
hangbanfile<<*p;
p=p->next;
}
}
hangbanfile.flush();
hangbanfile.close();
cout<<"以上信息数据已保存到磁盘中!"<<endl;
}
flymessage *readalldata() // 从文件中读取航班信息数据
{
fstream hangbanfile;
flymessage *p,*head,*q;
q=head=new flymessage;
head->next=NULL;
hangbanfile.open("航班的基本信息数据.dat",ios::in);
hangbanfile>>head->counter;
if(head->counter==0)
{
cout<<"文件中没有任何数据"<<endl;
return head;
}
for(int i=0;i<head->counter;i++)
{
p=new flymessage;
p->next=NULL;
q->next=p;
q=p;
hangbanfile>>*p;
}
hangbanfile.flush();
hangbanfile.close();
return head;
}
//---------------------------------------------------------------------------------------
bool writemessage() // 录入信息,建立数据文件
{
flymessage *hangban,*p,*q,*s;
double ct;
char ach[20],bch[20],ch,hbd[10];
int fcd,mst;
seat st[4];
daytime lefttime,arrivetime;
cout<<"请输入航班起点城市名:";
cin>>bch;
cout<<"请输入航班到达城市名:";
cin>>ach;
cout<<"请输入航班号:";
cin>>hbd;
cout<<"请输入飞机号:";
cin>>fcd;
cout<<"请输入改航班的最大容量:";
cin>>mst;
cout<<"请输入该飞机"<<bch<<"起飞时间:星期 小时 分钟";
cin>>lefttime.weekday>>lefttime.hour>>lefttime.minute;
cout<<"请输入该飞机到达"<<ach<<"的时间:星期 小时 分钟";
cin>>arrivetime.weekday>>arrivetime.hour>>arrivetime.minute;
for(int i=1;i<4;i++)
{
st[i].chars=i;
cout<<"请输入"<<i<<"等舱的价格票价:";
cin>>st[i].price;
cout<<"请输入"<<i<<"等舱的剩余量:";
cin>>st[i].leftseat;
}
cout<<"请输入航线的打折情况:";
cin>>ct;
hangban=new flymessage;
hangban->didbook=0;
strcpy(hangban->begcity,bch);
strcpy(hangban->arrivecity,ach);
hangban->flycode=fcd;
strcpy(hangban->hangbancode,hbd);
hangban->maxseat=mst;
hangban->lefttime.weekday=lefttime.weekday;
hangban->lefttime.hour=lefttime.hour;
hangban->lefttime.minute=lefttime.minute;
hangban->arrivetime.weekday=arrivetime.weekday;
hangban->arrivetime.hour=arrivetime.hour;
hangban->arrivetime.minute=arrivetime.minute;
hangban->count=ct;
for( i=1;i<4;i++)
{
hangban->seats[i].chars=i;
hangban->seats[i].price=st[i].price;
hangban->seats[i].leftseat=st[i].leftseat;
}
hangban->empty=true;
s=p=new flymessage;
p=readalldata();
q=p->next;
if(p->next==NULL)
{
hangban->counter=1;
savealldata(hangban);
}
else
{
while(q!=NULL)
{
s->next=q;
s=q;
q=q->next;
}
s->next=hangban;
hangban->next=NULL;
p->counter++;
savealldata(p);
}
cout<<"是否继续录入y/n?"<<endl;
cin>>ch;
while(1)
{
if((ch=='y')||(ch=='Y'))
return true;
else if((ch=='n')||(ch=='N'))
return NULL;
else
{
cout<<"输入错误,请重新输入";
cin>>ch;
}
}
}
//----------------------------------------------------------------------------------
void changecode() // 管理人员修改密码
{
fstream change;
operater administ;
cout<<"请输入你的新用户名: ";
cin>>administ.name;
cout<<"请输入你的新密码: ";
cin>>administ.code;
change.open("管理员密码文件.dat",ios::in|ios::out|ios::binary);
if(!change)
{
cout<<"修改密码出错! 修改失败!"<<endl;
}
change.write((char*)(&administ),sizeof(operater));
change.flush();
change.close();
system("cls");
}
//------------------------------------------------------------------------------------
operater getcode() // 在文件中读取密码,与用户输入的密码核对
{
fstream fin;
operater admini;
fin.open("管理员密码文件.dat",ios::in);
fin.read((char*)(&admini),sizeof(operater));
fin.close();
return admini;
}
//----------------------------------------------------------------------------------------
void savealldatatoguest(guestmessage *guest)
{
fstream guestdata;
guestmessage *p;
p=guest->next;
guestdata.open("客户信息库.dat",ios::out);
guestdata<<guest->sum<<endl;
if(guest->sum==1)
guestdata<<*guest;
else
{
while(p!=NULL)
{
guestdata<<*p;
p=p->next;
}
}
guestdata.flush();
guestdata.close();
cout<<"信息已经保存在了客户信息库了!"<<endl;
}
guestmessage *readguest()
{
fstream guestfile;
guestmessage *guest,*p,*q;
q=guest=new guestmessage;
guest->next=NULL;
guestfile.open("客户信息库.dat",ios::in);
guestfile>>guest->sum;
if(guest->sum==0)
return guest;
else
for(int i=0;i<guest->sum;i++)
{
p=new guestmessage;
p->next=NULL;
q->next=p;
q=p;
guestfile>>*p;
}
guestfile.flush();
guestfile.close();
return guest;
}
void showmessage(flymessage *p)
{
cout<<"航班号 : "<<p->hangbancode<<" 飞机号: "<<p->flycode<<endl;
cout<<"**************************"<<endl;
cout<<"营运时间: 每周"<<p->lefttime.weekday<<" "<<p->lefttime.hour<<"点"<<p->lefttime.minute<<"分,从 "<<p->begcity<<" 起飞,到达 "<<p->arrivecity<<" 的时间是 周"<<p->arrivetime.weekday<<" "<<p->arrivetime.hour<<"点"<<p->arrivetime.minute<<"分"<<endl;
cout<<"********************************************************************"<<endl;
cout<<"票价打 "<<p->count<<" 折. "<<endl;
cout<<"**************************"<<endl;
cout<<"一等舱的剩余量为: "<<p->seats[1].leftseat<<" 一等舱票价为 "<<p->seats[1].price<<endl;
cout<<"二等舱的剩余量为: "<<p->seats[2].leftseat<<" 二等舱票价为 "<<p->seats[2].price<<endl;
cout<<"三等舱的剩余量为: "<<p->seats[3].leftseat<<" 三等舱票价为 "<<p->seats[3].price<<endl;
cout<<endl;
}
//---------------------------------------------------------------------------------
void chaxun() // 客户查询信息
{
fstream hangban,name,citye;
int a;
flymessage *flymess,*p;
guestmessage *guest,*q;
CX: cout<<"请选择查询方法 1 按航班号查询, 2 按姓名查询, 3按抵达城市名查询"<<endl<<"你选择的是: ";
cin>>a;
if(a==1)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -