航空机票订票系统设计 (1)设计管理员模块和用户功能模块 (2)在管理员模块中可以添加、删除和修改航线的信息,如起点终点站名、航班号、飞机号、飞机周日(星期几)、乘员定额等。 (3)在客户模块中可以进行订票、退票、修改、查询订定票的信息(包括姓名、订票量、舱位等级1,2或3)等; (3)结合基本操作的单链表、队列、二叉树等数据结构以及排序算法,设计实现机票订票系统的查询、订票、退票等功能; (4)设计并实现人机交互友好的界面或菜单。请写出C++完整代码
时间: 2023-08-31 14:53:52 浏览: 461
民航机票预订系统 结合MFC界面编程 具有订票、退票,客户及航班查询等功能.rar
以下是一个基于C++的简单机票订票系统的示例代码,包括管理员模块和用户功能模块:
```cpp
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
// 航班类
class Flight {
private:
string flightNumber;
string startPoint;
string endPoint;
string aircraftNumber;
string dayOfWeek;
int capacity;
public:
Flight(string fNum, string start, string end, string aNum, string day, int cap)
: flightNumber(fNum), startPoint(start), endPoint(end), aircraftNumber(aNum), dayOfWeek(day), capacity(cap) {}
// 获取航班信息
void getFlightInfo() {
cout << "航班号:" << flightNumber << endl;
cout << "起点站:" << startPoint << endl;
cout << "终点站:" << endPoint << endl;
cout << "飞机号:" << aircraftNumber << endl;
cout << "周几:" << dayOfWeek << endl;
cout << "乘员定额:" << capacity << endl;
}
// 获取座位容量
int getCapacity() {
return capacity;
}
};
// 管理员类
class Administrator {
private:
map<string, Flight*> flights; // 使用map存储航班信息
public:
// 添加航班信息
void addFlight(string fNum, string start, string end, string aNum, string day, int cap) {
Flight* newFlight = new Flight(fNum, start, end, aNum, day, cap);
flights[fNum] = newFlight;
cout << "航班添加成功!" << endl;
}
// 删除航班信息
void deleteFlight(string fNum) {
if (flights.find(fNum) != flights.end()) {
delete flights[fNum];
flights.erase(fNum);
cout << "航班删除成功!" << endl;
} else {
cout << "航班不存在!" << endl;
}
}
// 修改航班信息
void modifyFlight(string fNum, string start, string end, string aNum, string day, int cap) {
if (flights.find(fNum) != flights.end()) {
Flight* flight = flights[fNum];
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
flight->getFlightInfo();
delete flights[fNum];
Flight* newFlight = new Flight(fNum, start, end, aNum, day, cap);
flights[fNum] = newFlight;
cout << "航班修改成功!" << endl;
} else {
cout << "航班不存在!" << endl;
}
}
};
// 用户类
class User {
private:
vector<Flight*> bookedFlights;
public:
// 订票
void bookTicket(Flight* flight) {
if (flight != nullptr) {
bookedFlights.push_back(flight);
cout << "订票成功!" << endl;
} else {
cout << "订票失败,航班不存在!" << endl;
}
}
// 退票
void cancelTicket(Flight* flight) {
if (flight != nullptr) {
for (auto it = bookedFlights.begin(); it != bookedFlights.end(); ++it) {
if (*it == flight) {
bookedFlights.erase(it);
cout << "退票成功!" << endl;
return;
}
}
cout << "您未订购该航班的机票!" << endl;
} else {
cout << "退票失败,航班不存在!" << endl;
}
}
// 查询订票信息
void queryBookedFlights() {
if (bookedFlights.empty()) {
cout << "您尚未订购任何机票!" << endl;
} else {
cout << "您已订购的机票信息如下:" << endl;
for (Flight* flight : bookedFlights) {
flight->getFlightInfo();
cout << endl;
}
}
}
};
int main() {
Administrator admin;
User user;
// 添加航班信息
admin.addFlight("F001", "Beijing", "Shanghai", "A001", "Monday", 100);
admin.addFlight("F002", "Shanghai", "Beijing", "A002", "Tuesday", 150);
// 用户订票
Flight* flight1 = admin.getFlight("F001");
user.bookTicket(flight1);
// 用户退票
user.cancelTicket(flight1);
// 查询订票信息
user.queryBookedFlights();
return 0;
}
```
请注意,以上代码只是一个简单的示例,仅包含了基本的功能和数据结构。你可以根据实际需求进行扩展和修改,添加更多的功能和错误处理。希望对你有所帮助!
阅读全文