Advertisement
Guest User

Untitled

a guest
May 19th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.84 KB | None | 0 0
  1. /*
  2. BankSystemDriver.cpp: BankSystem is a project that allows users to dynamically look at and change particular values of their bank and credit accounts.  Upon execution,
  3.                       the user is given a number of choices for actions to take.  They are allowed to validate their card (and identify it), check their balance, enter
  4.                       a new account into the system, or remove an account from the system.  
  5.  
  6. Author: Jake Davis [41441080]
  7. Date Modified: 14 April 2010
  8. UserID / Lab: z7c7 / L2A
  9. */
  10.  
  11. #include "stdafx.h"
  12. #include "CreditAccount.h"
  13. #include <iostream>
  14. #include <string>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. #define NUM_ACCOUNTS 100
  19.  
  20. BankAccount* newBankAccount(){
  21.     string newName;
  22.     string newNum;
  23.     double newBalance;
  24.  
  25.     cout << "\nEnter account name: ";
  26.     cin >> newName;
  27.     cout << "Enter bank account number (10 digits: 0-9): ";
  28.     cin >> newNum;
  29.     cout << "Enter initial balance: $";
  30.     cin >> newBalance;
  31.  
  32.     // Create the account
  33.     BankAccount* theAccount = new BankAccount(newName, newNum, newBalance);
  34.  
  35.     // Confirmation of completion
  36.     cout << "\nAccount successfully created. Returning value.\n\n";
  37.     theAccount->print();
  38. }
  39.  
  40. void newCreditAccount(CreditAccount* account){
  41.     string newName;
  42.     string newNum;
  43.     double newBalance;
  44.     int cardType;
  45.     string newCredNum;
  46.     double newInterest;
  47.     int credChoice;
  48.     string digits;
  49.  
  50.     while(true){
  51.  
  52.     cout << "\nEnter account name: ";
  53.     cin >> newName;;
  54.     while(newNum.length() != 10){
  55.         cout << "Enter bank account number (10 digits: 0-9): ";
  56.         cin >> newNum;
  57.         // Validate that this number has not already been taken!
  58.  
  59.         if(newNum.length() != 10){
  60.             cout << "Invalid number of digits (must be 10 digits: 0-9)\n\n";
  61.             continue;
  62.         }
  63.     }
  64.     cout << "Enter initial balance: $";
  65.     cin >> newBalance;
  66.     cout << "\nSelect a credit card type from the options below:\n";
  67.     cout << "1. MasterCard\n";
  68.     cout << "2. Visa\n";
  69.     cout << "3. American Express\n";
  70.     cout << "4. Discover\n";
  71.     cout << "0. Cancel\n";
  72.     cout << "Please select one: ";
  73.     cin >> cardType;
  74.  
  75.     if(cardType == 0) break;
  76.     if(cardType < 0 && cardType > 4) cout << "Sorry, you've entered an invalid option\n\n";
  77.  
  78.     /* Credit card standards include:
  79.             MasterCard: first two digits 51, 52, 53, 54, or 55; 16 digits in length
  80.             Visa: first digit 4; 13 or 16 digits in length
  81.             American Express: first digits 34 or 37; 15 digits in length
  82.             Discover: first digits 6011; 16 digits in length
  83.     */
  84.  
  85.     // Begin switch statement to determine the type of credit card the user wants
  86.     switch(cardType){
  87.         case 1:
  88.             while(digits.length() != 14){
  89.                 cout << "Per MasterCard standards, the first two digits must be 51, 52, 53, 54, or 55.\nFor simplicity, we will choose 54 for you!\nEnter the remaining 14 digits (0-9): ";
  90.                 newCredNum = "54";
  91.                 cin >> digits;
  92.                 if(digits.length() != 14) cout << "Ruht-roh! Invalid number of digits (must be 14 digits: 0-9)\n\n";
  93.                 else newCredNum.append(digits);
  94.             }
  95.             break;
  96.         case 2:
  97.             while(digits.length() != 12 && digits.length() != 15){
  98.                 cout << "Per Visa standards, the first digit of your card must be 4.\nEnter 12 or 15 additional digits (0-9): ";
  99.                 newCredNum = "4";
  100.                 cin >> digits;
  101.                 if(digits.length() != 12 && digits.length() != 15) cout << "Ruht-roh! Invalid number of digits (must be 12 or 15 digits: 0-9)\n\n";
  102.                 else newCredNum.append(digits);
  103.             }
  104.             break;
  105.         case 3:
  106.             while(digits.length() != 13){
  107.                 cout << "Per American Express standards, the first digit of your card must be 34 or 37.\nFor simplicity, we will choose 34 for you!\nEnter the remaining 13 digits (0-9): ";
  108.                 newCredNum = "34";
  109.                 cin >> digits;
  110.                 if(digits.length() != 13) cout << "Ruht-roh! Invalid number of digits (must be 13 digits: 0-9)\n\n";
  111.                 else newCredNum.append(digits);
  112.             }
  113.             break;
  114.         case 4:
  115.             while(digits.length() != 12){
  116.                 newCredNum = "6011";
  117.                 cout << "Per Discover standards, the first four digits of your card must be 6011.\nEnter the remaining 12 digits (0-9): ";
  118.                 cin >> digits;
  119.                 if(digits.length() != 12) cout << "Ruht-roh! Invalid number of digits (must be 12 digits: 0-9)\n\n";
  120.                 else newCredNum.append(digits);
  121.             }
  122.             break;
  123.         default:
  124.             break;
  125.     }
  126.  
  127.     cout << "\nSelect an interest plan from the below options:\n";
  128.     cout << "1. 5.0%, $10/yearly" << endl;
  129.     cout << "2. 19.0%, $2/yearly" << endl;
  130.     cout << "3. 24.0%, $0/yearly" << endl;
  131.     cout << "0. Cancel new credit card account" << endl;
  132.     cout << "Please select one: ";
  133.     cin >> credChoice;
  134.  
  135.     if(credChoice == 0) break;
  136.     if(credChoice != 1 && credChoice != 2 && credChoice != 3) cout << "Sorry, you've entered an invalid option\n";
  137.  
  138.     switch(credChoice){
  139.         case 1:
  140.             newInterest = 5;
  141.             break;
  142.         case 2:
  143.             newInterest = 19;
  144.             break;
  145.         case 3:
  146.             newInterest = 24;
  147.             break;
  148.         default:
  149.             break;
  150.     }
  151.    
  152.     // Create the account based on the values received
  153.     account->setName(newName);
  154.     account->setNum(newNum);
  155.     account->setBal(newBalance);
  156.     account->setCredBal(0.0 );
  157.     account->setCredNum(newCredNum);
  158.     account->setInterest(newInterest);
  159.  
  160.     // Confirmation of completion
  161.     cout << "\nAccount successfully created. Returning value.\n\n";
  162.     account->print();
  163.     }
  164. }
  165.  
  166.  
  167. int main(void){
  168.  
  169.     int choice;
  170.     int entry;
  171.     string tempAcc;
  172.     BankAccount* bankArray[NUM_ACCOUNTS];
  173.  
  174.     bankArray[0] = new BankAccount("Jake Davis", "1234567890", 100.00);
  175.  
  176.     while(true){
  177.         cout << "\nPlease choose from the following options:\n" << endl;
  178.         cout << "1. Enter a new account into the system\n";
  179.         cout << "2. Remove an account from the system\n";
  180.         cout << "3. Check your account\n";
  181.         cout << "0. Exit\n";
  182.         cout << "Please select one: ";
  183.         cin >> choice;
  184.  
  185.         // account1.print();
  186.  
  187.         if(choice == 0) break;
  188.         if(choice < 1 || choice > 3){
  189.             cout << "Sorry, you've entered an invalid option\n";
  190.             continue;
  191.         }
  192.        
  193.         switch(choice){
  194.             case 1:
  195.                 cout << "\nPlease select the type of account you want to create:\n";
  196.                 cout << "1. Bank (debit card) account\n";
  197.                 cout << "2. Credit card account\n";
  198.                 cout << "0. Cancel new account\n";
  199.                 cout << "Please select one: ";
  200.                 cin >> entry;
  201.                 if(entry == 0) break;
  202.                 else if(entry != 1 && entry != 2){
  203.                     cout << "Sorry, you've entered an invalid option\n";
  204.                     continue;
  205.                 }
  206.                 else{
  207.                     if(entry == 1) bankArray[1] = newBankAccount(bankArray[0]);     // add to the given array the return of newBankAccount()
  208.                     if(entry == 2) bankArray[1] = newCreditAccount();               // add to the given array the return of newCreditAccount()
  209.                 }
  210.                 break;
  211.             case 2:
  212.                 cout << "Enter bank account number: ";
  213.                 cin >> tempAcc;
  214.                 /*
  215.                 if(bankArray.findNum(tempAcc)){
  216.                    
  217.                 }
  218.                 else{
  219.                     cout << "\nThis bank account number was not found!";   
  220.                 }
  221.                 */
  222.                 break;
  223.             case 3:
  224.                 cout << "Enter bank account number: ";
  225.                 cin >> tempAcc;
  226.                 /*
  227.                 findNum(tempAcc);
  228.                 */
  229.                 break;
  230.             default:
  231.                 break;
  232.         }
  233.     }
  234.     return 0;
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement