c++stl航空管理系统
时间: 2023-09-15 18:23:10 浏览: 97
C++ STL(标准模板库)可以用于开发航空管理系统,以下是一个简单的示例:
首先,定义一个航班类表示航班信息:
```c++
class Flight {
public:
string flightNumber; // 航班号
string departure; // 出发地
string destination; // 目的地
string departureTime; // 出发时间
string arrivalTime; // 到达时间
Flight(string fnum, string dep, string dest, string dtime, string atime) {
flightNumber = fnum;
departure = dep;
destination = dest;
departureTime = dtime;
arrivalTime = atime;
}
};
```
然后,定义一个航班信息管理类,用于添加、删除和查询航班信息:
```c++
class FlightManager {
private:
vector<Flight> flights;
public:
void addFlight(Flight flight) {
flights.push_back(flight);
}
void removeFlight(string flightNumber) {
for (auto it = flights.begin(); it != flights.end(); ++it) {
if (it->flightNumber == flightNumber) {
flights.erase(it);
break;
}
}
}
vector<Flight> searchFlight(string departure, string destination) {
vector<Flight> result;
for (auto it = flights.begin(); it != flights.end(); ++it) {
if (it->departure == departure && it->destination == destination) {
result.push_back(*it);
}
}
return result;
}
};
```
最后,可以编写一个主函数测试这个航空管理系统:
```c++
int main() {
FlightManager manager;
// 添加航班信息
manager.addFlight(Flight("CA123", "Beijing", "Shanghai", "2022-01-01 08:00", "2022-01-01 10:00"));
manager.addFlight(Flight("MU456", "Shanghai", "Guangzhou", "2022-01-01 12:00", "2022-01-01 14:00"));
manager.addFlight(Flight("CZ789", "Guangzhou", "Beijing", "2022-01-01 16:00", "2022-01-01 18:00"));
// 查询航班信息
vector<Flight> flights = manager.searchFlight("Beijing", "Shanghai");
for (auto it = flights.begin(); it != flights.end(); ++it) {
cout << it->flightNumber << " " << it->departure << " " << it->destination << " " << it->departureTime << " " << it->arrivalTime << endl;
}
// 删除航班信息
manager.removeFlight("CA123");
return 0;
}
```
这个示例只是一个简单的航空管理系统,实际开发中需要根据具体需求进行调整和扩展。
阅读全文