Advertisement
Koalaazz

Bank Program v1

Apr 22nd, 2021
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.07 KB | None | 0 0
  1. //more with classes YEAHAHAHYYA
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. #include <xpolymorphic_allocator.h>
  7. using namespace std;
  8.  
  9. struct bankAccount //structure
  10. {
  11.     string Address;
  12.     string NewAddress;
  13.     string City;
  14.     string State;
  15.     string Zip;
  16.     string AccNum;
  17.     string Fname;
  18.     string Lname;
  19.     string Street;
  20.     string NewStreet;
  21.     char AccType;
  22.     double Balance;
  23.     double AddBalance;
  24.     double IntRate;
  25.     double AddIntRate;
  26.     int AccountNumber;
  27.     int EnterAccNum;
  28. };
  29. vector <bankAccount> EpicBank;
  30. bankAccount newAcc;
  31.  
  32. class Bank2
  33. {
  34.  
  35. public:
  36.     int NextAccNum = 1;
  37.     int counter = 0, counterValue;
  38.     int info[4];
  39.     string AddName;
  40.     string ChangeName;
  41.     string line;
  42.     vector<string> NewName;
  43.     vector<string> InfoList;
  44.     vector<string> ::iterator it;
  45.  
  46.     void OpenFile() //file, not needed yet
  47.     {
  48.         ifstream infoFile;
  49.         infoFile.open("info.txt");
  50.         if (infoFile.is_open())
  51.         {
  52.             cout << "Info File Opened\n";
  53.         }
  54.         else cout << "Unable to open info file. The location may have changed or the file may be damaged.";
  55.     }
  56.  
  57.  
  58.     void menu() //main menu
  59.     {
  60.         string useChoice;
  61.         char choice;
  62.         bool flag = true;
  63.         do
  64.         {
  65.             cout << "Choose an option: \n";
  66.             cout << "1. Change Account Name\n";
  67.             cout << "2. Make Deposit\n";
  68.             cout << "3. Add Interest\n";
  69.             cout << "4. Change Address\n";
  70.             cout << "5. Search Name\n";
  71.             cout << "6. Search City\n";
  72.             cout << "7. Add An Account\n";
  73.             cout << "8. Display account information\n";
  74.             cout << "9. Quit\n";
  75.             cin >> useChoice; //users choice
  76.             int usingAccount;
  77.  
  78.             choice = useChoice[0];
  79.  
  80.             switch (choice)
  81.             {
  82.             case '1': // change name
  83.             {
  84.                 changeName();
  85.                 break;
  86.             }
  87.             case '2': //make deposit
  88.             {
  89.                 MakeDeposit();
  90.                 break;
  91.             }
  92.             case '3': //add interest
  93.             {
  94.                 AddInterest();
  95.                 break;
  96.             }
  97.             case '4': //change address
  98.             {
  99.                 ChangeStreet();
  100.                 break;
  101.             }
  102.             case '5': //search by name
  103.             {
  104.                 SearchName();
  105.                 system("PAUSE");
  106.                 system("CLS");
  107.                 break;
  108.             }
  109.             case '6': //search by city, not working
  110.             {
  111.                 SearchCity();
  112.                 system("CLS");
  113.                 break;
  114.             }
  115.             case '7': //adds new account
  116.             {
  117.                 AddAccount();
  118.                 break;
  119.             }
  120.             case '8': //display account into
  121.             {
  122.                 DisplayInfo();
  123.                 break;
  124.             }
  125.             case '9': //quits
  126.             {
  127.                 flag = false;
  128.                 break;
  129.             }
  130.             default: //if user presses wrong key
  131.             {
  132.                 cout << "You have pressed an incorrect key. Please try again.\n";
  133.                 system("CLS");
  134.             }
  135.             }
  136.         } while (flag == true); //sets bool false, quitting program
  137.     }
  138.     int accGet()
  139.     {
  140.         int accNum;
  141.         bool foundAcc = false;
  142.         int useAcc;
  143.  
  144.         system("CLS");
  145.         cout << "\nEnter Account Number ";
  146.         cin >> accNum;
  147.  
  148.         // Checks if it is a valid input
  149.         while (!cin)
  150.         {
  151.             cout << "Invalid selection.  Please enter account number only\n\n"; //invalid selection change
  152.             cin.clear();
  153.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  154.             cin >> accNum;
  155.         }
  156.  
  157.         // Finds the account with the matching number
  158.         for (int i = 0; i < EpicBank.size(); i++)
  159.         {
  160.             if (accNum == EpicBank[i].AccountNumber)
  161.             {
  162.                 useAcc = i;
  163.                 foundAcc = true;
  164.             }
  165.         }
  166.  
  167.         // Lets the user know whether their account was found
  168.         if (foundAcc == false)
  169.         {
  170.             cout << "\nNo account found\n";
  171.             system("PAUSE");
  172.         }
  173.         else
  174.         {
  175.             cout << "\nAccount " << EpicBank[useAcc].AccountNumber << " has been found" << endl;
  176.             system("PAUSE");
  177.             return useAcc;
  178.         }
  179.     }
  180.     void changeName() //changes first and last name
  181.     {
  182.         int useAcc = accGet();
  183.         system("CLS");
  184.         cout << "\nPlease enter your new first name\n";
  185.         cin >> ChangeName;
  186.         EpicBank[useAcc].Fname = ChangeName;
  187.         cout << "\nPlease enter your new last name\n";
  188.         cin >> ChangeName;
  189.         EpicBank[useAcc].Lname = ChangeName;
  190.         system("PAUSE");
  191.         system("CLS");
  192.     }
  193.     void AddAccount() //add account function
  194.     {
  195.         system("CLS");
  196.         char NewAccType;
  197.         string newInfo;
  198.         int newBal;
  199.         cout << "\nPlease Enter The Following Info:  "; //asks for all info
  200.         cout << "\n\nFirst: ";
  201.         cin >> newInfo;
  202.         newAcc.Lname = newInfo;
  203.         cout << "\nLast: ";
  204.         cin >> newInfo;
  205.         newAcc.Fname = newInfo;
  206.         cout << "\nAddress number: ";
  207.         cin >> newInfo;
  208.         newAcc.Address = newInfo;
  209.         cout << "\nCity: ";
  210.         cin >> newInfo;
  211.         newAcc.City = newInfo;
  212.         cout << "\nStreet: ";
  213.         cin >> newInfo;
  214.         newAcc.Street = newInfo;
  215.         cout << "\nState: ";
  216.         cin >> newInfo;
  217.         newAcc.State = newInfo;
  218.         cout << "\nZip code: ";
  219.         cin >> newInfo;
  220.         newAcc.Zip = newInfo;
  221.         cout << "\nEnter C or S for checking or savings: ";
  222.         cin >> NewAccType;
  223.         newAcc.AccType = NewAccType;
  224.         cout << "\nEnter a balance: ";
  225.         cin >> newBal;
  226.         newAcc.Balance = newBal;
  227.         cout << "\nEnter an interest rate: ";
  228.         cin >> newBal;
  229.         newAcc.IntRate = newBal;
  230.  
  231.         newAcc.AccountNumber = NextAccNum;
  232.         NextAccNum++; //increments next account number
  233.  
  234.         cout << "\n\nYour account has been set up with the number: " << newAcc.AccountNumber << endl; //shows account number
  235.         EpicBank.push_back(newAcc);
  236.         system("PAUSE");
  237.         system("CLS");
  238.     }
  239.  
  240.     void DisplayInfo() //just displays info
  241.     {
  242.         int useAcc = accGet();
  243.         cout << "\nName: " << EpicBank[useAcc].Fname << " " << EpicBank[useAcc].Lname << "\n";
  244.         cout << "Balance: " << EpicBank[useAcc].Balance << "\n";
  245.         cout << "Interest Rate: " << EpicBank[useAcc].IntRate << "\n";
  246.         cout << "City: " << EpicBank[useAcc].City << "\n";
  247.         cout << "State: " << EpicBank[useAcc].State << "\n";
  248.         cout << "Street: " << EpicBank[useAcc].Street << "\n";
  249.         cout << "Number Address: " << EpicBank[useAcc].Address << "\n";
  250.         cout << "Account Number: " << EpicBank[useAcc].AccountNumber << "\n";
  251.         cout << "Account Type: " << EpicBank[useAcc].AccType << "\n";
  252.         system("PAUSE");
  253.         system("CLS");
  254.     }
  255.  
  256.     void MakeDeposit() //adds money
  257.     {
  258.         system("CLS");
  259.         int useAcc = accGet();
  260.         cout << "Please Make A Deposit: ";
  261.         cin >> EpicBank[useAcc].AddBalance;
  262.         EpicBank[useAcc].Balance = EpicBank[useAcc].AddBalance + EpicBank[useAcc].Balance;
  263.         system("PAUSE");
  264.         system("CLS");
  265.     }
  266.  
  267.     void AddInterest() //adds interest
  268.     {
  269.         system("CLS");
  270.         int useAcc = accGet();
  271.         cout << "Please Add Interest: ";
  272.         cin >> EpicBank[useAcc].AddIntRate;
  273.         EpicBank[useAcc].IntRate = EpicBank[useAcc].AddIntRate + EpicBank[useAcc].IntRate;
  274.         system("PAUSE");
  275.         system("CLS");
  276.     }
  277.  
  278.     void ChangeStreet() //changes street
  279.     {
  280.         system("CLS");
  281.         int useAcc = accGet();
  282.         cout << "Please Enter your Address Number: ";
  283.         cin >> EpicBank[useAcc].NewAddress;
  284.         EpicBank[useAcc].Address = EpicBank[useAcc].NewAddress;
  285.         cout << "Please Enter your Street Name: ";
  286.         cin >> EpicBank[useAcc].NewStreet;
  287.         EpicBank[useAcc].Street = EpicBank[useAcc].NewStreet;
  288.         system("PAUSE");
  289.         system("CLS");
  290.     }
  291.  
  292.     void SearchCity()
  293.     {
  294.         // Asks for the city they want to search for
  295.         system("CLS");
  296.         int useAcc = accGet();
  297.         string findcity;
  298.         cout << "\nWhat city would you like to search for?\n";
  299.         cin >> findcity;
  300.  
  301.         cout << "\n\nSearching...\n";
  302.         cout << "\nAll results for " << findcity << " are shown below\n\n";
  303.  
  304.         // Searches for a matching city in the accounts
  305.         for (int i = 0; i < EpicBank.size(); i++)
  306.         {
  307.             if (EpicBank[i].City == findcity)
  308.             {
  309.                 // Displays the account number, name, and city
  310.                 cout << (i + 1) << " " << EpicBank[i].Lname << ", " << EpicBank[i].Fname << ", " << EpicBank[i].City << endl;
  311.                 system("PAUSE");
  312.             }
  313.         }
  314.     }
  315.  
  316.     void SearchName()
  317.     {
  318.  
  319.         // Asks for the name they want to search for
  320.         system("CLS");
  321.         int useAcc = accGet();
  322.         string name;
  323.         cout << "\nWhat name would you like to search for?\n";
  324.         cin >> name;
  325.         cout << "\n\nSearching...\n";
  326.         system("PAUSE");
  327.         system("CLS");
  328.         cout << "\nAll results for " << name << " are shown below\n\n";
  329.         // Searches for a matching name in the accounts
  330.         for (int i = 0; i < EpicBank.size(); i++)
  331.         {
  332.             if (EpicBank[i].Fname == name || EpicBank[i].Lname == name)
  333.             {
  334.                 // Displays the account number and name
  335.                 cout << (i + 1) << " " << EpicBank[i].Lname << ", " << EpicBank[i].Fname << endl;
  336.             }
  337.         }
  338.     }
  339. };
  340.  
  341.  
  342. int main()
  343. {
  344.     Bank2 Bank;
  345.     //Bank.OpenFile();
  346.     Bank.menu();
  347.     return 0;
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement