fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class User
  5. {
  6. public:
  7. int userid;
  8. static int allusers;
  9. string email, password;
  10. bool isLoggedIn;
  11.  
  12. User(string email, string password)
  13. {
  14. this->email = email;
  15. this->password = password;
  16. this->userid = ++allusers;
  17. this->isLoggedIn = false;
  18. }
  19.  
  20. void login(string email, string password)
  21. {
  22. if (this->email == email && this->password == password)
  23. {
  24. cout << "Login successful\n";
  25. isLoggedIn = true;
  26. }
  27. else if (this->email == email)
  28. {
  29. cout << "Wrong password\n";
  30. }
  31. else
  32. {
  33. cout << "Wrong email\n";
  34. }
  35. }
  36.  
  37. void logout()
  38. {
  39. if (isLoggedIn)
  40. {
  41. cout << "User with email " << email << " has logged out.\n";
  42. isLoggedIn = false;
  43. }
  44. else
  45. {
  46. cout << "User is not logged in.\n";
  47. }
  48. }
  49.  
  50. void changepassword(string oldPassword, string newPassword)
  51. {
  52. if (this->password == oldPassword)
  53. {
  54. this->password = newPassword;
  55. cout << "Password changed successfully.\n";
  56. }
  57. else
  58. {
  59. cout << "Old password is wrong\n";
  60. }
  61. }
  62. };
Success #stdin #stdout 0s 5264KB
stdin
Standard input is empty
stdout
Standard output is empty