User 类的函数实现如下:
```cpp
// 构造函数
User::User(string name, string pwd) {
username = name;
password = pwd;
}
// 登录函数
bool User::login() {
string inputPwd;
cout << "Please enter your password: ";
cin >> inputPwd;
if (inputPwd == password) {
cout << "Login successful!" << endl;
return true;
} else {
cout << "Incorrect password. Login failed." << endl;
return false;
}
}
// 注册函数
bool User::registerUser() {
string inputPwd1, inputPwd2;
cout << "Please enter a new password: ";
cin >> inputPwd1;
cout << "Please confirm the password: ";
cin >> inputPwd2;
if (inputPwd1 != inputPwd2) {
cout << "Passwords do not match. Registration failed." << endl;
return false;
} else {
password = inputPwd1;
cout << "Registration successful!" << endl;
return true;
}
}
// 显示预订航班信息函数
void User::displayBookings() const {
if (bookings.empty()) {
cout << "You have no bookings." << endl;
} else {
cout << "Your bookings:" << endl;
for (const Flight& flight : bookings) {
cout << flight << endl;
}
}
}
// 预订航班函数
bool User::bookFlight(const vector& flights) {
int choice;
cout << "Available flights:" << endl;
for (int i = 0; i < flights.size(); i++) {
cout << i+1 << ". " << flights[i] << endl;
}
cout << "Please enter the number of the flight you want to book: ";
cin >> choice;
if (choice < 1 || choice > flights.size()) {
cout << "Invalid choice. Booking failed." << endl;
return false;
} else {
int numSeats;
cout << "Please enter the number of seats you want to book: ";
cin >> numSeats;
if (!flights[choice-1].book(numSeats)) {
cout << "Booking failed. Not enough seats available." << endl