Flight 类的函数实现如下:
```cpp
// 构造函数
Flight::Flight(string no, string dep, string dest, string time, int cap, double p) {
flightNo = no;
departure = dep;
destination = dest;
departureTime = time;
capacity = cap;
reserved = 0;
price = p;
}
// 显示函数
void Flight::display() const {
cout << "Flight No.: " << flightNo << endl;
cout << "Departure: " << departure << endl;
cout << "Destination: " << destination << endl;
cout << "Departure Time: " << departureTime << endl;
cout << "Capacity: " << capacity << endl;
cout << "Reserved: " << reserved << endl;
cout << "Price: " << price << endl;
}
// 预订座位函数
bool Flight::book(int num) {
if (num <= 0 || reserved + num > capacity) {
return false;
}
reserved += num;
return true;
}
// 修改票价函数
bool Flight::changePrice(double newPrice) {
if (newPrice <= 0) {
return false;
}
price = newPrice;
return true;
}
// 修改座位数函数
bool Flight::changeCapacity(int newCap) {
if (newCap < reserved) {
return false;
}
capacity = newCap;
return true;
}
// 取消预订座位函数
bool Flight::cancel(int num) {
if (num <= 0 || num > reserved) {
return false;
}
reserved -= num;
return true;
}
// 比较运算符
bool Flight::operator==(const Flight& other) const {
return flightNo == other.flightNo;
}
// 友元函数,用于输出航班信息
ostream& operator<<(ostream& os, const Flight& flight) {
os << "Flight No.: " << flight.flightNo << endl;
os << "Departure: " << flight.departure << endl;
os << "Destination: " << flight.destination << endl;
os << "Departure Time: " << flight.departureTime << endl;
os << "Capacity: " << flight