为了实现多文件形式,我们需要将不同的函数分别写在不同的文件中,并且需要在主程序中包含这些文件。下面是一个可能的实现方式:
首先,我们可以将航班和订单的结构体定义放在一个头文件`flight.h`中:
```c++
#ifndef FLIGHT_H
#define FLIGHT_H
#include
#include
struct Flight {
std::string flightNo; // 航班号
std::string date; // 日期
std::string time; // 时间
int seats; // 座位数
double price; // 票价
};
struct Order {
std::string flightNo; // 航班号
std::string name; // 姓名
std::string id; // 身份证号码
};
void addFlight(std::vector& flights);
void queryFlight(const std::vector& flights);
void bookTicket(std::vector& flights, std::vector& orders);
void cancelTicket(std::vector& flights, std::vector& orders);
void queryOrder(const std::vector& orders);
#endif
```
然后,我们将各个函数分别写在不同的源文件中。例如,`flight.cpp`中包含添加航班和查询航班的函数:
```c++
#include "flight.h"
#include
#include
using namespace std;
// 添加航班
void addFlight(vector& flights) {
Flight flight;
cout << "请输入航班号:";
cin >> flight.flightNo;
cout << "请输入日期:";
cin >> flight.date;
cout << "请输入时间:";
cin >> flight.time;
cout << "请输入座位数:";
cin >> flight.seats;
cout << "请输入票价:";
cin >> flight.price;
flights.push_back(flight);
cout << "添加航班成功!" << endl;
}
// 查询航班
void queryFlight(const vector& flights) {
string flightNo;
cout << "请输入要查询