Advertisement
Guest User

Simples Simulação

a guest
Sep 23rd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <string>
  5. using namespace std;
  6.  
  7. void mainMenu();
  8. void start();
  9.  
  10. class UserRoot
  11. {
  12. public:
  13.     std::string root_username;
  14.     std::string root_password;
  15.  
  16.     void setRootUsername(std::string _root_username_)
  17.     {
  18.         this->root_username = _root_username_;
  19.     }
  20.    
  21.     void setRootPassword(std::string _root_password_)
  22.     {
  23.         this->root_password = _root_password_;
  24.     }
  25.    
  26.     friend ostream& operator<<(ostream& archive, const UserRoot& root)
  27.     {
  28.         archive << std::endl << "USER: " << root.root_username << std::endl <<
  29.                 "PASSWORD: " << root.root_password;
  30.         return archive;
  31.     }
  32. };
  33.  
  34. UserRoot root;
  35.  
  36. int main()
  37. {
  38.     mainMenu();
  39. }
  40.  
  41. void mainMenu()
  42. {
  43.     char user_option;
  44.    
  45.     std::cout << std::endl << "\t\tWELCOME TO LINUX OS" << std::endl;
  46.     std::cout << std::endl << "\t\t1_SET YOUR SETTINGS" <<std::endl;
  47.     std::cout << "\t\t2_ENTER IN SYSTEM" << std::endl;
  48.     std::cout << "\t\t3_EXIT" << std::endl;
  49.     std::cout << std::endl << "\t\tOption: ";
  50.     std::cin >> user_option;
  51.    
  52.       switch(user_option)
  53.       {
  54.           case '1':
  55.           {
  56.                 try
  57.                 {
  58.                   start();  
  59.                 } catch(const char *Exception) {
  60.                   std::cerr << Exception;
  61.                 }  
  62.           }
  63.          
  64.           case '2':
  65.           {
  66.  
  67.           }
  68.          
  69.           case '3':
  70.           {
  71.              
  72.           }
  73.       }
  74. }
  75.  
  76. void start()
  77. {
  78.     std::string username;
  79.     std::string password;
  80.    
  81.     std::cout << std::endl << "\t\tSET YOUR NEW SETTINGS" << std::endl;
  82.     std::cin.ignore();
  83.    
  84.      std::cout << std::endl << "\t\tUSERNAME: ";
  85.      std::getline(cin, username);
  86.        if(username.empty())
  87.            throw "\t\tFAIL. STR EMPTY";
  88.      root.setRootUsername(username);
  89.            
  90.      std::cout << "\t\tPASSWORD: ";
  91.      std::getline(cin, password);
  92.        if(password.empty())
  93.            throw "\t\tFAIL. STR EMPTY";
  94.      root.setRootPassword(password);
  95.      
  96.      ofstream archive("RootSettings.txt", fstream::app);
  97.      
  98.      archive << root;
  99.      
  100.      archive.close();
  101.      exit(0);
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement