航空机票订票系统设计 (1)采用链式存储结构,设计每条航线所涉及的信息,如起点终点站名、航班号、飞机号、飞机周日(星期几)、乘员定额、余票量、订定票的客户名单(包括姓名、订票量、舱位等级1,2或3)等; (2)设计实现机票订票系统的查询、订票、退票等功能; (3)设计并实现人机交互友好的界面或菜单。 请写出C++完整代码
时间: 2023-08-31 07:55:03 浏览: 176
以下是一个简单的C++代码示例,演示了航空机票订票系统的设计:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 航班信息结构体
struct Flight {
string start;
string destination;
string flightNumber;
string aircraftNumber;
string weekDay;
int capacity;
int availableSeats;
vector<string> passengerList;
};
// 航班管理类
class FlightManagementSystem {
private:
vector<Flight> flights;
public:
// 添加航班
void addFlight(Flight flight) {
flights.push_back(flight);
}
// 查询航班
void searchFlights(string start, string destination, string weekDay) {
cout << "Available flights from " << start << " to " << destination << " on " << weekDay << ":" << endl;
for (const auto& flight : flights) {
if (flight.start == start && flight.destination == destination && flight.weekDay == weekDay) {
cout << "Flight Number: " << flight.flightNumber << endl;
cout << "Aircraft Number: " << flight.aircraftNumber << endl;
cout << "Available Seats: " << flight.availableSeats << endl;
cout << endl;
}
}
}
// 订票
void bookTicket(string flightNumber, string passengerName) {
for (auto& flight : flights) {
if (flight.flightNumber == flightNumber && flight.availableSeats > 0) {
flight.passengerList.push_back(passengerName);
flight.availableSeats--;
cout << "Ticket booked successfully!" << endl;
return;
}
}
cout << "Sorry, the flight is either full or does not exist." << endl;
}
// 退票
void cancelTicket(string flightNumber, string passengerName) {
for (auto& flight : flights) {
if (flight.flightNumber == flightNumber) {
for (auto it = flight.passengerList.begin(); it != flight.passengerList.end(); ++it) {
if (*it == passengerName) {
flight.passengerList.erase(it);
flight.availableSeats++;
cout << "Ticket canceled successfully!" << endl;
return;
}
}
}
}
cout << "Sorry, the ticket does not exist." << endl;
}
};
int main() {
FlightManagementSystem fms;
// 添加航班信息
Flight flight1 = {"New York", "Los Angeles", "AA123", "A123", "Monday", 100, 100, {}};
Flight flight2 = {"Los Angeles", "New York", "AA456", "A456", "Tuesday", 120, 120, {}};
fms.addFlight(flight1);
fms.addFlight(flight2);
// 查询航班
fms.searchFlights("New York", "Los Angeles", "Monday");
// 订票
fms.bookTicket("AA123", "John Doe");
// 退票
fms.cancelTicket("AA123", "John Doe");
return 0;
}
```
这只是一个简单的示例,实际的航空机票订票系统可能需要更复杂的功能和数据管理。你可以根据需求进行适当的修改和扩展。
阅读全文