Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. /*jadi gini, ku mau buat program username-password sederhana.
  2.  
  3. proses yang direncanakan kek gini:
  4. di fungsi main, parameter username sama password di set.
  5. naah pas program di 'run'
  6. user akan memasukkan input:
  7. 1. un, apabila un == username, lanjutkan ke; jika tidak, ulangi
  8. 2. pw, apabila pw == password, program selesai; jika tidak, ulangi.
  9. */
  10.  
  11. #include <iostream>
  12. #include <string>
  13.  
  14. using namespace std;
  15.  
  16.  
  17. class req
  18. {
  19.  
  20.  
  21. public:
  22.     string username;
  23.     string password;
  24.  
  25.     string getUn()
  26.     {
  27.         return username;
  28.     }
  29.     void setUn(string username)
  30.     {
  31.         this->username = username;
  32.     }
  33.  
  34.     string getPw()
  35.     {
  36.         return password;
  37.     }
  38.     void setPw(string password)
  39.     {
  40.         this->password = password;
  41.     }
  42.  
  43.     void enterName()
  44.     {
  45.         string un;
  46.         cout << "Username: ";
  47.         cin >> un;
  48.         if(un == username)
  49.         {
  50.             enterPassword();
  51.         }
  52.         else if (un != username)
  53.         {
  54.             cout << "wrong, try again!" << endl;
  55.             enterName();
  56.         }
  57.     }
  58.  
  59.     void enterPassword()
  60.     {
  61.         string pw;
  62.         cout << "Password: ";
  63.         cin >> pw;
  64.  
  65.         if(pw == password)
  66.         {
  67.             cout << ", Good to go!";
  68.         }
  69.         else if (pw != password)
  70.         {
  71.             cout << "wrong, try again!" << endl;
  72.             enterPassword();
  73.         }
  74.     }
  75.  
  76. };
  77.  
  78.  
  79.  
  80. int main()
  81. {
  82.     req myself;
  83.     myself.setUn("self");
  84.     myself.setPw("idklol");
  85.  
  86.     req oof;
  87.     oof.enterName();
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement