加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
user.cpp 6.23 KB
一键复制 编辑 原始数据 按行查看 历史
Lyan 提交于 2023-06-13 18:05 . added individual display for seat number
#include "database.cpp"
#include <string.h>
// 123
// 录入航班信息
int inputSeatClass()//判定座位数输入是否正确
{
char x;
cin >> x;
if(x >= '0' && x <= '2')
return x - '0';
else
{
cout << "输入错误,请重新输入[0,1,2]" << endl;
return inputSeatClass(); // 递归直到输入正确为止,有stack overflow的风险,但应该没事,下面同理
}
}
int inputSeatCount(int minVal)//判定座位数输入是否正确
{
char c[200];
cin >> c;
int temp=0;
for(int i=0;i<strlen(c);i++)
{
if('0'>c[i]||c[i]>'9')
{
cout<<"输入错误,请重新输入"<<endl;
temp=1;
break;
}
}
if(temp)
return inputSeatCount(minVal);
stringstream ss;
ss<<c;
int x;
ss>>x;
if(x >= minVal)
return x;
else
{
cout << "输入错误,请重新输入" << endl;
return inputSeatCount(minVal);
}
}
int addFlight(FL_Node& FL) {
string destination;
string flight_num;
string flight_regist;
string flight_data;
int maxseat[3];
int bookedseat[3]={0,0,0};
cout<<"请输入终点站名";
cin>>destination;
cout<<"请输入航班号";
cin>>flight_num;
cout<<"请输入飞机注册号";
cin>>flight_regist;
cout<<"请输入飞行日期";
cin>>flight_data;
// 检测是否有终点站、航班号、飞行日期相同的航班
FL_Node p = FL;
while (p != NULL)
{
if (p->destination == destination && p->flightno == flight_num && p->date == flight_data)
{
cout << "已存在相同航班" << endl;
return ERROR;
}
p = p->next;
}
cout<<"请输入头等舱额定座位数";
maxseat[0] = inputSeatCount(0);
cout<<"请输入商务舱额定座位数";
maxseat[1] = inputSeatCount(0);
cout<<"请输入经济舱额定座位数";
maxseat[2] = inputSeatCount(1);
new_flight(FL,destination,flight_num,flight_regist,flight_data,maxseat,bookedseat);
return OK;
}
void queryRoute(FL_Node FL_head, const string &flight_destination) // 查询航班
{
FL_Node p = FL_head;
bool found = false;
string lastDate = p->date;
while (p != NULL)
{
if (p->destination == flight_destination)
{
cout<<endl;
found = true;
cout << "航班号:" << p->flightno << endl;
cout << "飞机注册号:" << p->registerno << endl;
cout << "飞行星期:" << p->date << endl;
// 查找最近一天的航班日期
FL_Node q = p->next;
while (q != NULL && q->destination == flight_destination)
{
lastDate = q->date;
q = q->next;
}
// 输出余票量
int availableSeats = 0;
for (int i = 0; i < 3; i++)
{
availableSeats += p->maxseat[i] - p->bookedseat[i];
}
cout << "总余票额:" << availableSeats << endl;
int temp = p->maxseat[0] - p->bookedseat[0];
cout << (temp ? "头等舱余票:" + to_string(temp) : "头等舱无票") << endl;
temp = p->maxseat[1] - p->bookedseat[1];
cout << (temp ? "商务舱余票:" + to_string(temp) : "商务舱无票") << endl;
temp = p->maxseat[2] - p->bookedseat[2];
cout << (temp ? "经济舱余票:" + to_string(temp) : "经济舱无票") << endl;
//break;
}
p = p->next;
}
cout <<endl<< "最近一天航班日期:" << lastDate << endl;
cout<<endl;
if (!found)
{
cout << "未找到符合条件的航班信息!" << endl;
}
}
void input_tbs(char &ch) // 功能输入,A要,B不要
{
char s[100];
cin >> s;
if (strlen(s) == 1)
{
if (s[0] == 'A' || s[0] == 'B')
ch = s[0];
if (s[0] == 'a' || s[0] == 'b')
ch = s[0];
}
else
{
cout << "输入的功能无效,请重新输入" << endl;
input_tbs(ch);
}
}
void input_flight_num(FL_Node FL, char flight_num[]) // 航班号输入
{
FL_Node p = FL;
cin >> flight_num;
int temp = 1;
while (p)
{
if (p->flightno == flight_num)
{
temp = 0;
break;
}
p = p->next;
}
if (temp)
{
cout << "输入的航班号错误,请重新输入" << endl;
input_flight_num(FL, flight_num);
}
}
int ticket_booking_service(FL_Node &FL, const string name, const string flighnum,const string date_num,int ticket_num, int seat_class) // 订票服务
{
int flag = 1;
char ch;
FL_Node p = FL; // p指向预定的航班节点
while (p)
{
if (p->flightno == flighnum&&p->date==date_num)
break;
p = p->next;
}
if(p==NULL)
{
cout<<"您输入的航班飞行日期或航班号有误,请重新确认"<<endl;
return 0;
}
int code = new_PA(p, name, seat_class, ticket_num);
if (code == ERROR)
{
cout << "很抱歉无法满足您的需求,此次订票失败" << endl;
flag = 0;
}
else if (code == -1)
{
cout << "是否需要排队候补(A需要,B不需要)" << endl;
cout << "请输入指令";
input_tbs(ch);
switch (ch)
{
case 'a':
case 'A':
code = new_PAW(p, name, seat_class, ticket_num);
if (code == ERROR)
{
cout << "很抱歉无法满足您的需求,候补失败" << endl;
flag = 0;
}
else if (code == OK)
{
cout << "已为您加入候补名单" << endl;
flag = 0;
}
break;
case 'B':
case 'b':
cout << "很抱歉无法满足您的需求,此次订票失败" << endl;
flag = 0;
break;
default:
cout << "输入出错" << endl;
flag = 0;
break;
}
}
return flag;
}
int ticket_refund_service(FL_Node &FL,char name[],char flight_num[],char flight_date[])//rnm,退票
{
FL_Node p=FL;
int flag=1;
while(p)
{
if(p->date==flight_date&&p->flightno==flight_num)
{
flag=0;
break;
}
p=p->next;
}
if(flag)
{
cout<<"航班号或飞行日期输入错误,请重新确认"<<endl;
return ERROR;
}
if(del_PA(p,name))
return OK;
if(del_PAW(p,name))
return OK;
cout << "未找到该乘客!" << endl;
return ERROR;
return ERROR;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化