Question
Our goal in this project is to create a simple banking system which allows a banker to manage different bank accounts. As a banker, you
Our goal in this project is to create a simple banking system which allows a banker to manage different bank accounts. As a banker, you would create new accounts, deposit to an account, withdraw from an account, transfer money from one account to another, delete account, sort the accounts, or do inspection on one or all bank accounts. In order to do this job, you would need the tool for each of those items. The bank maintains a list of accounts.
Write a program in C++ to meet the above requirements. The list of account has to be available as long as you run the program. This means the list of the account has to be initialized in the main() function. Write a function for each of the items above. You will call these functions to perform any task on the bank accounts. Each account will have account number, name (last, first), balance and status (active/deactive). The header file, function file, and main file are as the sample below. All functions are of type void. You will fill in the necessary function parameters.
In order to do this project, you would need to understand pointers, functions, and vectors among other basic C++ knowledge. You will follow the exact requirement and format of the program. Any unnecessary changes will result in points taken off.
Attahced is my code. It goes header file, function file, main file. I cant seem to figure out where it is failing but it wont run correctly. Any help is appriciated.
Header:
#include
using namespace std; void menu(); void makeAccount(); void printAccount(); void transfer(); void PrintAllAccounts(); void depositAccount(); void ActiveDeactive(); void withdrawAccount(); void sortAccounts(); // sort the accounts using the account numbers void deleteAccount();
struct Account { int AccountNumber; string lastName; string firstName; double accountBalance; bool active; };
Function File:
void menu(int *num) {
int select = 0; cout << "Welcome! Select options below:" << endl; cout << "\t1. Make new account." << " \t2. Deposit to an account." << " \t3. Withdraw from an account." << " \t4. Transfer money." << " \t5. Print account." << " \t6. Activate/Deactivate an account." << " \t7. Delete an account." << " \t8. Display all accounts." << " \t9. Quit." << endl;
cout << "Selection:\t";
cin >> select; *inputPtr = select; }
void makeAccount(vector
Account temp;
temp.AccountNumber = rand() % 8999 + 1000; cout << "This bank account is index number: " << temp.AccountNumber << endl;
cout << "Last Name: " << endl; cin >> temp.lastName;
cout << "First Name: " << endl; cin >> temp.firstName;
cout << "Starting Balance :" << endl; cin >> temp.accountBalance;
bankAccounts.push_back(temp); }
void printAccount(vector
int accountNum; cout << "What account would you like to view? " << endl; cin >> accountNum; for (i=bankAccounts.begin(); i !=bankAccounts.end() && (*i).AccountNumber != accountNum; i++){ if ((*i).AccountNumber == accountNum) { cout << "Account Number: " << accountNum; cout << setw(4); cout << "Balance: " << (*i).accountBalance; cout << endl; cout << "Last Name: " << (*i).lastName; cout << setw(4); cout << "First Name: " << (*i).firstName << endl << endl; } else { cout << "Invalid Account Number." << endl; } } }
void transfer(vector
vector
cout << "From which account would you like to make a transfer from? Please enter account number: " << endl; cin >> accountFrom; cout << endl << "From which account would you like to make a transfer to? Please enter account number: " << endl; cin >> accountTo; cout << "How much would you like to transfer? :" << endl; cin >> transAmount;
for(j = bankAccounts.begin(); j != bankAccounts.end() && (*j).AccountNumber != accountFrom; j++) { for (i = bankAccounts.begin(); i != bankAccounts.end() && (*i).AccountNumber != accountTo; i++) { if (accountFrom = bankAccounts[j].AccountNumber) { tempF = bankAccounts[i].accountBalance; bankAccounts[i].accountBalance = tempF - transAmount; cout << "The new balance for account " << accountFrom << "is " << bankAccounts[i].accountBalance; }
if (accountTo = bankAccounts[i].AccountNumber) { tempT = bankAccounts[i].accountBalance; bankAccounts[i].accountBalance = tempT + transAmount; cout << "The new balance for account " << accountTo << "is " << bankAccounts[i].accountBalance; } } } }
void PrintAllAccounts(vector
vector
for (i=bankAccounts.begin();i!=bankAccounts.end(); i++){ cout << "Account Number: " << bankAccounts[i].AccountNumber; cout << setw(4); cout << "Balance: " << bankAccounts[i].accountBalance; cout << endl; cout << "Last Name: " << bankAccounts[i].lastName; cout << setw(4); cout << "First Name: " << bankAccounts[i].firstName << endl << endl; } }
void depositAccount(vector
int deposAccount, deposAmount;
cout << "From which account would you like to make a deposit to? Please enter account number: " << endl; cin >> deposAccount; cout << "How much would you like to deposit? :" << endl; cin >> deposAmount;
vector
for (i=bankAccounts.begin();i!=bankAccounts.end() && (*i).AccountNumber != deposAccount; i++) { if ((*i).AccountNumber == deposAccount) { (*i).accountBalance += deposAmount; cout << "The new balance for account " << deposAccount << "is " << (*i).AccountBalance; } else{ cout << "Invalid Account Number." << endl; } } }
void ActiveDeactive(vector
int AcctNum;
cout << "What account would you like to activate or deactivate?" << endl; cin >> AcctNum;
vector
for (i = bankAccounts.begin(); i != bankAccounts.end && (*i).AccountNumber != AcctNum; i++) { if ((*i).AccountNumber == AcctNum) { cout << "The current status of bank account " << AcctNum << " is " << (*i).active << endl; if ((*i).active == true) { (*i).active == false; } else { (*i).active == true; } } } }
void withdrawAccount(vector
cout << "From which account would you like to make a withdraw from? Please enter account number: " << endl; cin >> withdrawAccount; cout << "How much would you like to withdraw? :" << endl; cin >> withdrawAmount;
vector
for (i=bankAccounts.begin();i!=bankAccounts.end() && (*i).AccountNumber != withdrawAccount; i++) { if ((*i).AccountNumber == withdrawAccount) { if (withdrawAmount <= ((*i).AccountBalance)) { (*i).accountBalance -= withdrawAmount; cout << "The new balance for account " << withdrawAccount << "is " << (*i).AccountBalance; } else{ cout << "Insufficient Funds"<< endl; } } else { cout << "Invalid Account Number." << endl; } } }
void sortAccounts(vector
for (i = bankAccounts.begin(); i != bankAccounts.end(); i++){ sort((*i).AccountNumber); } }
void deleteAccount(vector
cout << "What account would you like to delete?" << endl; cin >> delacct;
vector
Main File:
#include "header_file.h" #include "function_file.cpp"
int main(){
vector
int input = 0; int* inputPtr = &input;
menu(inputPtr);
while(input != 9) { switch (input) {
case 1: makeAccount(bankAccounts); break;
case 2: depositAccount(bankAccounts); break;
case 3: withdrawAccount(bankAccounts); break;
case 4: transfer(bankAccounts); break;
case 5: printAccount(bankAccounts); break;
case 6: ActiveDeactive(bankAccounts); break;
case 7: deleteAccount(bankAccounts); break;
case 8: PrintAllAccounts(bankAccounts); break;
case 9: return 0;
default : cout << "Invalid choice please enter a number between 0 and 9 from the menu above" << endl; } menu(inputPtr); } return 0; }
All is in C++. I was coding in CLion.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started