class Flight { private: string flightNo; // 航班号 string departure; // 出发地 string destination; // 目的地 stri

动态 未结 0 119
小小草
小小草 LV1 2023年9月23日 23:40 发表
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
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复