在管理员登录后,需要根据管理员的选择执行相应的操作。可以使用一个`while`循环来实现这个功能。具体代码如下:
```c++
if (admin.login()) {
while (true) {
cout << "Welcome, admin!" << endl;
cout << "1. Display all flights" << endl;
cout << "2. Add a new flight" << endl;
cout << "3. Delete a flight" << endl;
cout << "4. Modify a flight" << endl;
cout << "5. Logout" << endl;
int adminChoice;
cin >> adminChoice;
switch (adminChoice) {
case 1: {
// 显示所有航班信息
for (auto& flight : flights) {
cout << flight << endl;
}
break;
}
case 2: {
// 添加新航班
Flight newFlight = AdminUtil::addNewFlight();
flights.push_back(newFlight);
FileUtil::writeFlightsToFile(flights, flightFile);
cout << "New flight added successfully!" << endl;
break;
}
case 3: {
// 删除航班
string flightNumber = AdminUtil::getFlightNumber();
bool foundFlight = false;
for (auto it = flights.begin(); it != flights.end(); ++it) {
if (it->getFlightNumber() == flightNumber) {
foundFlight = true;
flights.erase(it);
FileUtil::writeFlightsToFile(flights, flightFile);
cout << "Flight deleted successfully!" << endl;
break;
}
}
if (!foundFlight) {
cout << "Flight not found." << endl;
}
break;
}
case 4: {
// 修改航班信息
string flightNumber = AdminUtil::getFlightNumber();
bool foundFlight = false;
for (auto& flight : flights) {
if (flight.getFlightNumber() == flightNumber) {
foundFlight = true;
AdminUtil::modifyFlight(flight);
FileUtil::writeFlightsToFile(flights, flightFile);
cout << "Flight modified successfully!" << endl;
break;
}
}
if (!foundFlight) {
cout