Advertisement
Guest User

User Manager

a guest
Nov 29th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.69 KB | None | 0 0
  1. //User Manager 1.0 by Ilir "Skifter" Prenku
  2. #include "windows.h"
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6.  
  7.  
  8. using namespace std;
  9. ///////////////////////////////////////////////Functions Used////////////////////////////////////////////////////
  10.  
  11. int LoginAttempts(int value);
  12. void loadingBar(int);
  13. void addNewUser();
  14. void CreateUser(char * firstn, char * lastn, float balance, short iD);
  15. void DisplayOptions();
  16. void newUser();
  17. char tab = '\t';
  18. bool status = 1;
  19.  
  20. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  21. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  22.  
  23.  
  24. class CreateAcc
  25. {
  26. public:
  27.     char  *fName, *lName;
  28.     short iD;
  29.     float EditBalance(float currentBalance, float addRemove) { currentBalance = (addRemove + currentBalance);   return currentBalance; };
  30.     float AddBalance(float balance) { currentBalance = balance; return balance; };
  31.     float dispBalance() {
  32.         float myBalance = currentBalance; return myBalance;
  33.     };
  34.  
  35. private:
  36.     float currentBalance;
  37.  
  38. };
  39.  
  40.  
  41. int main()
  42. {
  43.  
  44.  
  45.     system("title User Management SNC-SyS 1.0"); //Window Title - Programm Name
  46.     system("color E");
  47.     int input;
  48.  
  49.     if (!LoginAttempts(3))
  50.         cout << "Program will Exit.\n";
  51.     //else
  52.         //cout << "we can continue with the programm\n.";
  53.     else
  54.     {
  55.         do
  56.         {
  57.             DisplayOptions();
  58.             cout << "\n\nType in Your Option: ";
  59.             cin >> input;
  60.             switch (input)
  61.             {
  62.             case 0: status = 0;
  63.                 break;
  64.             case 1: cout << "Finding User";
  65.                 break;
  66.             case 2: addNewUser();
  67.                 break;
  68.             case 3: cout << "Add Remove Balance";
  69.                 break;
  70.             default: cout << "Give an Option from above.";
  71.                 break;
  72.             }
  73.             } while (status);
  74.  
  75.         }
  76.    
  77.     system("cls");
  78.     cout <<"\n\n\tThank you For Using SNC Softwares - Hope we'll see you soon...";
  79.     Sleep(3000);
  80.     exit(0);
  81.        
  82.     system("pause");
  83.     return 0;
  84. }
  85.  
  86. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  87. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                      
  88.  
  89.  
  90. void CreateUser(char * firstn, char * lastn, float balance, short iD)
  91. {
  92.     ofstream dataB;
  93.     system("cls");
  94.     cout << ".:==============================SNC/SYS==================================:.\n\n";
  95.     cout << "                   User Created ID:         " << iD << "                   \n";
  96.     cout << "===========================================================================\n";
  97.     CreateAcc account;
  98.     account.fName = firstn;
  99.     account.lName = lastn;
  100.     account.iD = iD;
  101.     account.AddBalance(balance);
  102.     cout << endl;
  103.     cout << "                 First Name: " << account.fName << endl;
  104.     cout << "                 Last Name:  " << account.lName << endl;
  105.     cout << "                 Balance:    " << account.dispBalance()<< endl;
  106.     cout << "===========================================================================\n";
  107.     dataB.open("database.txt");
  108.         dataB<< account.iD <<tab<<account.fName << tab << account.lName <<tab<< account.AddBalance(balance) << endl;
  109.         dataB.close();
  110.  
  111. }
  112.  
  113. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  114. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  115.  
  116. int LoginAttempts(int counter)
  117. {
  118.  
  119.     string usr, pass;
  120.     int login = 0;
  121.     cout << ".:==============================SNC/SYS==================================:.\n\n";
  122.     while (counter != 0)
  123.     {  
  124.         cout << "Username: ";
  125.         cin >> usr;
  126.         cout << "\nPassword: ";
  127.         cin >> pass;
  128.         if (usr == "admin" && pass == "skifteri")
  129.         {
  130.             counter = 0;
  131.             system("cls");
  132.             cout << "Connecting to License Server\n";
  133.             loadingBar(50);
  134.             cout << "\nLogged in Succesfully..\n";
  135.             Sleep(3000);
  136.             system("cls");
  137.             login = 1;
  138.  
  139.         }
  140.         else
  141.         {
  142.             counter--;
  143.             system("cls");
  144.             cout << ".:==============================SNC/SYS==================================:.\n\n";
  145.             cout << "Attempts left : " << counter <<" !!\n\n";
  146.             Beep(750, 300); Beep(750, 300); Beep(750, 300);
  147.            
  148.  
  149.             if (counter == 0 && (usr != "admin" || pass != "skifteri"))
  150.             {
  151.                 system("cls");
  152.                 system("color c");
  153.                
  154.                 cout << "Wrong User or Password... \nContact your system administrator."; Sleep(3000); exit(0);            
  155.                 login = 0;
  156.             }
  157.         }
  158.  
  159.     }
  160.     return login;
  161. };
  162. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  163. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  164.  
  165. void addNewUser()
  166. {
  167.     system("cls");
  168.     cout << "\t\t\t\tCreating New User to Database\n-----------------------------------------------------------------------------\n";
  169.     char fname[15], lname[15]; float balance; int iD;
  170.     cout << "Type the Firstname: ";
  171.     cin >> fname;
  172.     cout << endl;
  173.     cout << "Type the Lastname: ";
  174.     cin >> lname;
  175.     cout << endl;
  176.     cout << "Id Number: ";
  177.     cin >> iD;
  178.     cout << endl;
  179.     cout << "Type Balance: ";
  180.     cin >> balance;
  181.     CreateUser(fname, lname, balance, iD);
  182. };
  183.  
  184.  
  185. void DisplayOptions()
  186. {
  187.     cout << ".:==============================SNC/SYS==================================:.\n\n";
  188.     cout << "1. Find Account" << endl;
  189.     cout << "2. Create Account" << endl;
  190.     cout << "3. Add/Remove Balance to Account" << endl;
  191.     cout << "4. Edit Account" << endl;
  192.     cout << "5. Exit System" << endl;
  193. }
  194.  
  195. void loadingBar(int i)
  196. {
  197.     char load = ':';
  198.     cout << "STATUS: ";
  199.     for (i; i<100; i++)
  200.     {
  201.         Sleep(100);
  202.         cout << load;
  203.     }
  204.  
  205.     cout<<" Loaded 100%" ;  Sleep(1000);
  206. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement