Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.72 KB | None | 0 0
  1. //using std with cout and cin instead of namespace
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <ctime>
  6. #include <conio.h>
  7. #include <stdio.h>
  8.  
  9.  
  10.  
  11. struct User {
  12.     int acctNumber1;            //User account number 1
  13.     int acctNumber2;
  14.     double acctBalance1;        //user account balance 1
  15.     double acctBalance2;       
  16.     int acctInterest1;          //user account interest rate1
  17.     int acctInterest2;
  18.     char acctName[256];         //User account Name
  19.     char acctPass[256];         //user account password
  20.     int logInNumber;
  21.     bool isAdmin;
  22. } account[8999]; // 9999 - 1000 because we virtually start at record '1000'
  23.  
  24. void printSummary(int user) {
  25.     printf("\n\n"
  26.            "+-----------------+\n"
  27.            "| Account Summary |\n"
  28.            "+=================+\n\n"
  29.            "+-----------------------------------------------------+\n"
  30.            "| Account | Account number | Balance  | Interest Rate |\n"
  31.            "+---------+----------------+--------------------------+\n"
  32.            "| 1       | %d           | %.2lf                      \n"           //add interest rate 1 and 2
  33.            "| 2       | %d           | %.2lf                      \n\n\n",
  34.            account[user].acctNumber1, account[user].acctBalance1, account[user].acctNumber2, account[user].acctBalance2);
  35. }
  36.  
  37. void createAccount(int *n) {
  38.     *n = *n+1;
  39.     int *inputInt = new int[1];
  40.     std::cout << "Please Fill out the following information to create a new account" << std::endl;
  41.     std::cout << "Full name: ";
  42.     std::cin >> account[*n].acctName;
  43.     std::cout << "Password: ";
  44.     std::cin >> account[*n].acctPass;
  45.                
  46.     // get first account number
  47.     std::cout << "First account number: ";
  48.     std::cin >> *inputInt;
  49.     while(*inputInt < 1000 || *inputInt > 9999) { // check none of the users already have this account number, if they do keep prompting
  50.         std::cout   << "Account number invalid. Must be between 1000 and 9999.\n"
  51.                     << "------------------------------------------------------\n"
  52.                     << "First account number: ";                   
  53.         std::cin >> *inputInt;
  54.     }
  55.     account[*n].acctNumber1 = *inputInt; // valid (new) account number, add it to the user
  56.  
  57.     // get first account balance
  58.     std::cout << "First account Balance: ";
  59.     std::cin >> account[*n].acctBalance1;
  60.  
  61.     //check its between 0 and 100,000 else re ask
  62.  
  63.     //get first interest rate, check its between .01% and 15% else re ask
  64.  
  65.     // get second account number
  66.     std::cout << "Second account number: ";
  67.     std::cin >> *inputInt;
  68.     while(*inputInt < 1000 || *inputInt > 8999) { // check none of the users already have this account number, if they do keep prompting
  69.         std::cout   << "Account number invalid. Must be between 1000 and 9999.\n"
  70.                     << "------------------------------------------------------\n"
  71.                     << "Second account number: ";
  72.         std::cin >> *inputInt;
  73.     }
  74.     account[*n].acctNumber2 = *inputInt; // valid (new) account number, add it to the user
  75.  
  76.     //get second account balance
  77.     std::cout << "Second account balance: ";
  78.     std::cin >> account[*n].acctBalance2;
  79.  
  80.     //check its between 0 and 100,000 else re ask
  81.  
  82.     //get first interest rate, check its between .01% and 15% else re ask
  83.    
  84. }
  85.  
  86. void login(int *userId, int *loggedIn) {
  87.     char *inputText = new char[256];
  88.     std::cout << "Please enter username: ";
  89.     std::cin >> inputText;
  90.     for(int i = 0; i < 8999; i++) {
  91.         if ( strcmp (account[i].acctName, inputText) == 0 ) {
  92.             std::cout << "Welcome " << account[i].acctName << ", Please enter your password: " << std::endl; //move to logged in menu
  93.             std::cin >> inputText;
  94.             if ( strcmp (account[i].acctPass, inputText) == 0 ) {
  95.                 printSummary(i);
  96.                 std::cout << "Press [Enter] to continue" << std::endl;
  97.                 _getch();
  98.                 *loggedIn = 1;
  99.                 account[i].logInNumber++;
  100.                 *userId = i;
  101.             }
  102.             else {
  103.                 std::cout << "Incorrect password." << std::endl;
  104.                 break;
  105.             }
  106.         }
  107.     }
  108. }
  109.  
  110. void transferMoney(int *userId) {
  111.     double amount = 0.00;
  112.     bool enoughFunds = false;
  113.     std::cout   << "Please enter amount to transer: ";
  114.     std::cin    >> amount;
  115.     if(account[*userId].acctNumber1 == account[*userId].acctNumber2) {
  116.         printf( "   ^       +-----------+\n"
  117.                 " / ! \\     | Declined: |  Account numbers are the same.\n"
  118.                 "/____ \\    +-----------+\n\n");
  119.     }
  120.     if(amount > account[*userId].acctBalance1) {
  121.         printf( "   ^       +-----------+\n"
  122.                 " / ! \\     | Declined: |  Not enough founds in account number %d\n"
  123.                 "/____ \\    +-----------+\n\n",
  124.                 account[*userId].acctNumber1);
  125.     } else { enoughFunds = true; }
  126.     if(enoughFunds && (account[*userId].acctBalance1 - amount) < 10.00) {
  127.         printf( "+----------+\n"
  128.                 "| Warning: |   Account number %d now has a balance less than $10.00.\n"
  129.                 "+----------+\n\n",
  130.                 account[*userId].acctNumber1);
  131.         account[*userId].acctBalance2 += amount;
  132.         account[*userId].acctBalance1 -= amount;
  133.         std::cout << "Press [Enter] to continue" << std::endl;
  134.         enoughFunds = false; //prevent a second transfer happening
  135.     }
  136.     if(enoughFunds) {
  137.         if((amount + account[*userId].acctBalance2) > 100000.00) {
  138.             printf( "+----------+\n"
  139.                     "| Warning: |   Account number %d will have a balance greater\n"
  140.                     "+----------+   than the federally insurable amount of\n"
  141.                     "               $100,000.00 if you proceed.\n\n",
  142.                     account[*userId].acctNumber2);
  143.             char yn = 'x';     
  144.             // loop until the input is a y or n
  145.             while(yn != 'y' && yn != 'n') {
  146.                 std::cout << "Continue with transfer? Select [Y]es or [N]o" << std::endl;
  147.                 std::cin >> yn;
  148.             }
  149.             if(yn = 'n') {
  150.                 exit(0);
  151.             }
  152.         } else {
  153.             // make the transfer
  154.             account[*userId].acctBalance2 += amount;
  155.             account[*userId].acctBalance1 -= amount;
  156.             printf( "\n\n\n+--------------------+"
  157.                     "| Transfer complete. |"
  158.                     "+--------------------+\n\n\n");
  159.             printSummary(*userId);
  160.         }
  161.     }
  162.     std::cout << "Press [Enter] to continue" << std::endl;
  163.     _getch();
  164. }
  165.  
  166. void saveData() {//save all user account data to a csv file
  167. //ACCTNAME, ACCTNUMBER1, ACCTBALANCE1, ACCTINTEREST1, ACCTNUMBER2, ACCTBALANCE2, ACCT INTEREST2, PASSWORD,
  168. }
  169.  
  170. void accountDeposit(){
  171.    
  172.     int acctDepNum = 0;
  173.     int acctDepAmt = 0;
  174.  
  175.     std::cout   <<"Please enter the account number you wish to deposit to"<<endl
  176.                 <<"1."<<endl //user ACCTNUMBER 1
  177.                 <<"2."<<endl //user acctnumber 2
  178.                 <<endl;
  179.     std::cin>> acctDepNum;
  180.  
  181.     std::cout <<"Please enter deposit amount"<<endl;
  182.     std::cin>> acctDepNum;
  183.  
  184.     if (acctDepNum == 1){
  185.     acctbalance1 += acctDepAmt;
  186.     }
  187.     if (acctDepNum == 2){
  188.     acctbalance2 += acctDepAmt
  189.     }
  190.     save data //run save data
  191.     break //return to logged in menu
  192.     }
  193.  
  194. void accountWithdraw(){
  195.    
  196.     int acctWitNum = 0;
  197.     int acctWitAmt = 0;
  198.  
  199.     std::cout   <<"Please enter the account number you wish to deposit to"<<endl
  200.                 <<"1."<<endl //user ACCTNUMBER 1
  201.                 <<"2."<<endl //user acctnumber 2
  202.                 <<endl;
  203.     std::cin>>  acctWitNum;
  204.  
  205.     std::cout<<"Please enter deposit amount"<<endl;
  206.     std::cin>>acctWitNum
  207.  
  208.     if (acctDepNum == 1){
  209.     acctbalance1 += acctWitAmt;
  210.     }
  211.     if (acctDepNum == 2){
  212.     acctbalance2 += acctWitAmt
  213.     }
  214.     save data //run save data
  215.     break //return to logged in menu
  216.    
  217. }
  218.  
  219. void loggedInMenu(){
  220.  
  221.     int loggedinmenuselect = 0;
  222.         while (loggedinmenuselect == 0) {    //show menu when logged in is complete.
  223.     std::cout<< "Hello, acctname! Welcome to your account screen, Please select from the following menu: " >>
  224.     std::cin<< loggedinmenuselect;
  225.  
  226.     //1. account summary
  227.     if (loggedinmenuselect ==1){
  228.     printSummary(*userId);
  229.     }
  230.     //2. initiate balance transfer
  231.     if (loggedinmenuselect ==2){
  232.     transferMoney(*userId);
  233.     }
  234.     //3. deposit to account
  235.     if (loggedinmenuselect ==3){
  236.     printSummary(*userId);
  237.     }
  238.     //4. withdraw from account
  239.     if (loggedinmenuselect ==4){
  240.     printSummary(*userId);
  241.     }
  242.     //5. balance forecast
  243.     if (loggedinmenuselect ==5){
  244.     printSummary(*userId);
  245.     }
  246.     //6. exit
  247.     if (loggedinmenuselect ==6){
  248.         //savedata
  249.     //break;    Break;  Break;
  250.     }
  251. }
  252. int main()
  253. {
  254.     time_t _time;
  255.     struct tm timeinfo;
  256.     time ( &_time );
  257.     localtime_s (&timeinfo,&_time);
  258.  
  259.     // loops and menu initialisation
  260.     int n = 0;
  261.     int menuInput = 0;
  262.  
  263.                     //top level menu
  264.     int subMenuInput = 2;           //logged in account level menu
  265.     int loggedIn = 0;
  266.  
  267.     // user account details
  268.     int inputInt = 0;
  269.     int userId = 10000;
  270.  
  271.     std::cout << "Welcome to Interbanking Proprietary limited Super Squad" << std::endl;    //Welcome Message
  272.     //createAccount(&n);   
  273.     while (loggedIn == 0) // present the menu screen until the user logs in
  274.     {
  275.        
  276.         std::cout << "Please select from the following menu"    <<std::endl;    //Welcome Menu
  277.         std::cout << "1. Log in with existing bank account."    <<std::endl;
  278.         std::cout << "2. Create new bank account."              <<std::endl;
  279.         std::cin  >> menuInput;
  280.         if
  281.             (menuInput == 1)
  282.         {
  283.             login(&n, &loggedIn); // end option 1      
  284.         }
  285.         if (menuInput == 2)
  286.        
  287.         {
  288.             createAccount(&n); 
  289.                
  290.                 menuInput = 0;      }
  291.        
  292.         login(&userId, &loggedIn);
  293.        
  294.     } // end loggedIn loop
  295.  
  296. } // end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement