航空机票订票系统设计 (1)设计每条航线所涉及的信息,如起点终点站名、航班号、飞机号、飞机周日(星期几)、乘员定额、余票量、订定票的客户名单(包括姓名、订票量、舱位等级1,2或3)等; (2)结合基本操作的单链表、队列、二叉树等数据结构以及排序算法,设计实现机票订票系统的查询、订票、退票等功能; (3)设计并实现人机交互友好的界面或菜单。请写出C++完整代码,
时间: 2023-08-31 13:54:07 浏览: 38
以下是一个简单的C++代码示例,实现了航空机票订票系统的查询、订票、退票功能,并设计了一个基本的人机交互界面:
```cpp
#include <iostream>
#include <string>
#include <list>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
// 航班信息结构体
struct FlightInfo {
string startStation;
string endStation;
string flightNumber;
string aircraftNumber;
int weekday;
int passengerQuota;
int remainingTickets;
map<string, pair<int, int>> passengerList; // 客户名单,<姓名, <订票量, 舱位等级>>
};
// 航空机票订票系统类
class AirlineTicketSystem {
private:
list<FlightInfo> flightList; // 航班信息列表
public:
// 查询航班信息
void queryFlightInfo(string startStation, string endStation) {
for (const auto& flight : flightList) {
if (flight.startStation == startStation && flight.endStation == endStation) {
cout << "航班号:" << flight.flightNumber << endl;
cout << "飞机号:" << flight.aircraftNumber << endl;
cout << "飞机周日:" << flight.weekday << endl;
cout << "乘员定额:" << flight.passengerQuota << endl;
cout << "余票量:" << flight.remainingTickets << endl;
cout << "客户名单:" << endl;
for (const auto& passenger : flight.passengerList) {
cout << "姓名:" << passenger.first << ",订票量:" << passenger.second.first << ",舱位等级:" << passenger.second.second << endl;
}
return;
}
}
cout << "未找到符合条件的航班信息" << endl;
}
// 订票
void bookTicket(string flightNumber, string passengerName, int ticketQuantity, int cabinLevel) {
for (auto& flight : flightList) {
if (flight.flightNumber == flightNumber && flight.remainingTickets >= ticketQuantity) {
flight.remainingTickets -= ticketQuantity;
flight.passengerList[passengerName] = make_pair(ticketQuantity, cabinLevel);
cout << "订票成功!" << endl;
return;
}
}
cout << "订票失败,请检查航班号和余票量" << endl;
}
// 退票
void cancelTicket(string flightNumber, string passengerName) {
for (auto& flight : flightList) {
if (flight.flightNumber == flightNumber) {
auto it = flight.passengerList.find(passengerName);
if (it != flight.passengerList.end()) {
int ticketQuantity = it->second.first;
flight.remainingTickets += ticketQuantity;
flight.passengerList.erase(it);
cout << "退票成功!" << endl;
return;
}
}
}
cout << "退票失败,请检查航班号和乘客姓名" << endl;
}
// 添加航班信息
void addFlightInfo(FlightInfo flightInfo) {
flightList.push_back(flightInfo);
}
};
// 主函数
int main() {
AirlineTicketSystem ticketSystem;
// 添加航班信息
FlightInfo flight1 = {"Beijing", "Shanghai", "CA123", "B777", 1, 200, 180, {}};
FlightInfo flight2 = {"Shanghai", "Guangzhou", "MU456", "A320", 2, 150, 120, {}};
FlightInfo flight3 = {"Beijing", "Guangzhou", "CZ789", "B737", 3, 250, 220, {}};
ticketSystem.addFlightInfo(flight1);
ticketSystem.addFlightInfo(flight2);
ticketSystem.addFlightInfo(flight3);
// 人机交互菜单
while (true) {
cout << "请选择操作:" << endl;
cout << "1. 查询航班信息" << endl;
cout << "2. 订票" << endl;
cout << "3. 退票" << endl;
cout << "4. 退出" << endl;
int choice;
cin >> choice;
if (choice == 1) {
cout << "请输入起点站名和终点站名:" << endl;
string startStation, endStation;
cin >> startStation >> endStation;
ticketSystem.queryFlightInfo(startStation, endStation);
} else if (choice == 2) {
cout << "请输入航班号、乘客姓名、订票量和舱位等级:" << endl;
string flightNumber, passengerName;
int ticketQuantity, cabinLevel;
cin >> flightNumber >> passengerName >> ticketQuantity >> cabinLevel;
ticketSystem.bookTicket(flightNumber, passengerName, ticketQuantity, cabinLevel);
} else if (choice == 3) {
cout << "请输入航班号和乘客姓名:" << endl;
string flightNumber, passengerName;
cin >> flightNumber >> passengerName;
ticketSystem.cancelTicket(flightNumber, passengerName);
} else if (choice == 4) {
break;
} else {
cout << "无效的操作,请重新选择!" << endl;
}
}
return 0;
}
```
请注意,以上代码仅为一个简化的示例,实际情况中可能需要根据具体需求进行一些调整和优化。希望对你的设计有所帮助!