Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with upgrade the code, the requirement and originally code are below, inputs are marked Add the ability to store more than one

I need help with upgrade the code, the requirement and originally code are below, inputs are marked

Add the ability to store more than one account to your bank program using the list container from the Standard Template Library.

Your program should no longer automatically create an account when it starts. You will only create a new account when the user selects this as an option. First, create a new menu option that will enable the user to create a new account and implement functionality in your program that will allow the user to create a new account. Once the new account is added, store the new account in your list container. You will likely need to temporarily remove or comment out the code for some of the other menu functions to get this to work. You'll add those functions back later.

Hint: You'll need to include the library. You'll also need to declare a list that holds "Accounts" inside your main function, for example:list accounts;

Example input and output (input is underlined):

Main Menu: 0. Quit Program 1. Display account information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account Your choice: (input) Enter the name: (input) Enter the initial balance: (input)

Part 2.

Change the "Display account information" menu option to show all account information instead of just one account. When this option is selected, all of the stored accounts are shown. Use iterators to implement this option. The section in the reading called "Processing an Entire List" under "Iterators" will be helpful for this part of the task.

Example input and output (input is underlined):

Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account Your choice: (input 4) Enter the name: (input George) Enter the balance: (input 100) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account Your choice: (input 4) Enter the name: (input Harry) Enter the balance: (input 200) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account Your choice: (input 1) Account ID: 0 Name: George Balance: $100.00 Account ID: 1 Name: Harry Balance: $200.00

Part 3.

Add the ability to search through the container of accounts for a specific account and display the information associated with the account. Use iterators to find the account. If the account doesn't exist in the list, then display an appropriate error message. You should create a function that finds the desired account because you can reuse it later. This function should return an iterator. The section in the reading called "Returning Container Values from Functions" under "Iterators" will be helpful for this part of the task.

Example input and output (input is underlined):

Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 4) Enter the name: (input George) Enter the balance: (input 100) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: 4 Enter the name: (input Harry) Enter the balance: (input 200) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 5) Enter the ID of the account to find: (input 2) Account not found. Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 5) Enter the ID of the account to find: (input 1) Found account: Account ID: 1 Name: Harry Balance: $200.00

Part 4.

Fix the deposit and withdrawal options to work on any of the accounts in the system. First call the function you wrote for Part 3 of this task to find the desired account. After obtaining the iterator for the desired element in the container, dereference that iterator to apply the deposit or withdraw methods for that account. Alternatively, you can use the += or -= operators directly to the object in the container if you created these operators in the task last week. You must use iterators to find and modify the account. The section in the documentation called "Returning Container Values from Functions" under "Iterators" will be helpful for this part of the task.

Example input and output (input is underlined):

Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 4) Enter the name: (input George) Enter the balance: (input 100) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 4) Enter the name: (input Harry) Enter the balance: (input 200) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 2) Enter the ID of the account to find: (input 0) Found account: Account ID: 0 Name: George Balance: $100.00 Amount to deposit: (input 15) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 3) Enter the ID of the account to find: (input 1) Found account: Account ID: 1 Name: Harry Balance: $200.00 Amount to withdraw: (input 25) Account Menu: 0. Quit Program 1. Display Account Information 2. Add a deposit to an account 3. Withdraw from an account 4. Add new account 5. Find account by ID Your choice: (input 1) Account ID: 0 Name: George Balance: $115.00 Account ID: 1 Name: Harry Balance: $175.00

;---------------------------------------------------------------------------------------

#include #include using namespace std;

class BankAccount { private: int account_id; string account_name; float balance;

public: BankAccount(int id, string name, float bal) { this->account_id = id; this->account_name = name; this->balance = bal; }

void displayInfo() { cout << "Account ID: " << this->account_id << endl; cout << "Account Name: " << this->account_name << endl; cout << "Account Balance: $" << this->balance << endl; }

void deposit(float

amount) { this->balance += amount; }

void withdraw(float amount) { if (this->balance - amount >= 0) { this->balance -= amount; } else balance = 0; } };

int main() { string name; double balance; cout << "Enter the name: "; cin >> name; cout << " Enter the balance: "; cin >> balance;

BankAccount account(0, name, balance);

while (true) { cout << " Account Menu:" << endl; cout << "0. Quit Program" << endl; cout << "1. Display Account Information" <<

endl;

cout << "2. Add a deposit to an account" << endl; cout << "3. Withdraw from an account" << endl; cout << "Your choice: ";

int choice = 0; cin >> choice;

switch (choice) { case 0: return 0; case 1: account.displayInfo(); break; case 2: { float amount; cout << "Amount to deposit: "; cin >> amount; account.deposit(amount); break; } case 3: { float

amount; cout << "Amount to withdraw: "; cin >> amount; account.withdraw(amount); break; } } }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Does it avoid use of underlining?

Answered: 1 week ago