Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.17 KB | None | 0 0
  1. /*
  2. Name: Jacob Jimenez
  3. Section Number: 0146
  4. Operating System Used: Windows 10
  5. Compiler used: Visual Studio 2016
  6. Email: jacob.jime@gmail.com
  7. Latest date and time program last compiled and ran: 9/21/17 3:51 PM
  8. */
  9.  
  10. #include "BankAccountList.h";
  11.  
  12. int main1() {
  13.     BankAccount B1("1234", "Jacob", "Jim", 20.00);
  14.     BankAccount B2("4321", "John", "Doe", 20.01);
  15.     BankAccount B3("9087", "James", "Jones", 20.02);
  16.     BankAccountList BAL;
  17.     BAL.addAccount(B1);
  18.     BAL.addAccount(B2);
  19.     BAL.addAccount(B3);
  20.  
  21.     cout << BAL.toString() << endl;
  22.     bool found = false;
  23.     int index = -1;
  24.     found = BAL.findAccount("4321", index);
  25.     cout << index << endl;
  26.  
  27.     bool successfulDep = BAL.depositMoney("9087", 10.01);
  28.     cout << successfulDep << endl;
  29.  
  30.     bool successfulWith = BAL.withDrawMoney("9087", 10.00);
  31.     cout << successfulWith << endl;
  32.  
  33.     BAL.sort(1);
  34.  
  35.     cout << BAL.toString() << endl;
  36.  
  37.     BAL.sort(2);
  38.  
  39.     cout << BAL.toString() << endl;
  40.  
  41.     BAL.sort(3);
  42.  
  43.     cout << BAL.toString() << endl;
  44.  
  45.     int whereFound = -1;
  46.     bool isFound = BAL.findAccount("9087", whereFound);
  47.     cout << isFound << whereFound << endl;
  48.  
  49.     bool ifFound = BAL.deleteAccount("9087");
  50.     cout << ifFound << endl;
  51.     cout << BAL.toString() << endl;
  52.  
  53.  
  54.     system("pause");
  55.     return 0;
  56. }
  57.  
  58. int main() {
  59.     bool done = false;
  60.     bool isAdded = false;
  61.     int choice;
  62.     BankAccountList BAL;
  63.  
  64.     while (!done) {
  65.         cout << "Main Menu" << endl;
  66.         cout << "[1] Add new accounts using keyboard: " << endl
  67.             << "[2] Add new accounts using a data file (Limit = 30 accounts): " << endl
  68.             << "[3] Update an account: " << endl
  69.             << "[4] Close/delete an account: " << endl
  70.             << "[5] Write current account list to an output file in append mode: " << endl
  71.             << "[6] Print current account list to console: " << endl
  72.             << "[7] Withdraw Money from an account: " << endl
  73.             << "[8] Make Deposit to an account " << endl
  74.             << "[9] Balance inquiry " << endl
  75.             << "[10] Search account and show details (console only): " << endl
  76.             << "[11] Print current list description to console only " << endl
  77.             << "[12] Print list sorted by account number to console: " << endl
  78.             << "[13] Print list sorted by last name to console" << endl
  79.             << "[14] Print list sorted by balance to console: " << endl
  80.             << "[15] Exit " << endl;
  81.         cout << "Please enter a choice: " << endl;
  82.         cin >> choice;
  83.  
  84.         if (choice == 1) {
  85.             BAL.getInstance(BAL);
  86.             isAdded = true;
  87.         }
  88.         else if (choice == 2) {
  89.             // Setup for input file.
  90.             string inFileName;
  91.             cout << "Enter full path to input file: ";
  92.             cin.ignore();
  93.             getline(cin, inFileName);
  94.             //2. Bind file name with the ifstream object - Opening a connection to file
  95.             ifstream in(inFileName);
  96.  
  97.             if (in.is_open()) {
  98.                 BAL.getInstance(BAL, in);
  99.                 isAdded = true;
  100.             }
  101.             else {
  102.                 cout << "File could not be opened." << endl;
  103.             }
  104.         }
  105.         else if (isAdded && choice == 3) {
  106.             BAL.updateAccount();
  107.         }
  108.         else if (isAdded && choice == 4) {
  109.             string accN;
  110.             cout << "Please enter your account number: ";
  111.             cin >> accN;
  112.  
  113.             BAL.deleteAccount(accN);
  114.         }
  115.         else if (isAdded && choice == 5) {
  116.             // Setup for input file.
  117.             string outFile;
  118.             cout << "Enter full path to output file: ";
  119.             cin.ignore();
  120.             getline(cin, outFile);
  121.             //2. Bind file name with the ifstream object - Opening a connection to file
  122.             ofstream out(outFile, ios::app);
  123.  
  124.             if (out.is_open()) {
  125.                 BAL.print(out);
  126.             }
  127.             else {
  128.                 cout << "File could not be opened." << endl;
  129.             }
  130.         }
  131.         else if (isAdded && choice == 6) {
  132.             BAL.print();
  133.         }
  134.         else if (isAdded && choice == 7) {
  135.             double money;
  136.             string acct;
  137.             cout << "Please enter an account number: " << endl;
  138.             cin >> acct;
  139.             cout << "Please enter a withdrawl amount: $" << endl;
  140.             cin >> money;
  141.             BAL.withDrawMoney(acct, money);
  142.         }
  143.         else if (isAdded && choice == 8) {
  144.             double money;
  145.             string acct;
  146.             cout << "Please enter an account number: " << endl;
  147.             cin >> acct;
  148.             cout << "Please enter a deposit amount: $" << endl;
  149.             cin >> money;
  150.             BAL.depositMoney(acct, money);
  151.         }
  152.         else if (isAdded && choice == 9) {
  153.             string acct;
  154.             cout << "Please enter an account number: " << endl;
  155.             cin >> acct;
  156.             if (BAL.getBalance(acct) >= 0.00) {
  157.                 cout << "Balance for account number " << acct << ": " << "$" << BAL.getBalance(acct) << endl;
  158.             }
  159.             else {
  160.                 cout << "Account does not exist." << endl;
  161.             }
  162.         }
  163.         else if (isAdded && choice == 10) {
  164.             string acct;
  165.             cout << "Please enter an account number: ";
  166.             cin >> acct;
  167.             int index = -1;
  168.             bool isFound = BAL.findAccount(acct, index);
  169.             if (isFound == true && index != -1) {
  170.                 cout << left << setw(25) << BAL.getFirstName(acct) << setw(30) << BAL.getLastName(acct) << setw(30) << BAL.getBalance(acct) << endl;
  171.             }
  172.             else {
  173.                 cout << "Account was not found." << endl;
  174.             }
  175.         }
  176.         else if (isAdded && choice == 11) {
  177.             cout << BAL.listDescription() << endl;
  178.         }
  179.         else if (isAdded && choice == 12) {
  180.             BAL.sort(1);
  181.             BAL.print();
  182.         }
  183.         else if (isAdded && choice == 13) {
  184.             BAL.sort(2);
  185.             BAL.print();
  186.         }
  187.         else if (isAdded && choice == 14) {
  188.             BAL.sort(3);
  189.             BAL.print();
  190.         }
  191.         else if (choice == 15) {
  192.             done = true;
  193.         }
  194.     }
  195.  
  196.     system("pause");
  197.     return 0;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement