class User { private: string username; // 用户名 string password; // 密码 vector<Flight> bookings; // 预订的航班 publi

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