Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you modify the code below so that the user is prompted to enter their own account number when adding an account and another function

Can you modify the code below so that the user is prompted to enter their own account number when adding an account and another function accesible from the main menu called "Delete Account" where the user can search for their account using their account number and then are prompted to delete their account.

#include #include #include // std::setprecision

using namespace std;

class Account { private: string last_name; string first_name; double balance; string account_number; public: Account(string ac) { account_number = ac; }

void displayAccount() { cout << "Account number : " << account_number << endl; cout << "Account Holder First name : " << first_name << endl; cout << "Account Holder Last name : " << last_name << endl; cout << "Account Balance : " << balance << endl;

}

void setFirstName(string str) { first_name = str; } void setLastName(string str) { last_name = str; } void setBalance(double b) { balance = b; } string getFirstName() { return first_name; } string getLastName() { return last_name; } string getAccountNumber() { return account_number; } double getBalance() { return balance; } friend ostream& operator<<(ostream& os, const Account& at);

}; Account* acc[5]; int no_of_accounts = 0; int saving_acc = 1000; int current_acc = 1000;

// This is the overloaded opearator required as part of the question.

ostream& operator<<(ostream& os, const Account& at) { os << "Account Number : " << at.account_number << " First Name :" << at.first_name << " Last Name: " << at.last_name << " Account Balance : " << std::fixed << at.balance << " ";

return os; }

void displayBankAccounts() { cout << " -------DETAILS----------------" << endl; for (int i = 0; i < no_of_accounts; i++) { cout << *acc[i]; } }

void AddNewAccount() { cout << " -----------------------" << endl; if (no_of_accounts == 5) { cout << "Cannot add more than 5 accounts" << endl; return; } int response; string str; double bal; cout << "Do you want to add a Savings Account or Checking Account?" << endl; cout << "Type 1 for Savings and 2 for Checking" << endl; cin >> str;

string ac_no; if (!str.compare("1")) { ac_no = "SAV"; ac_no += to_string(saving_acc);

saving_acc++; } else if (!str.compare("2")) { ac_no = "CUR"; ac_no += to_string(current_acc); current_acc++; } else { cout << "Invalid response" << endl; return; } acc[no_of_accounts] = new Account(ac_no); cout << "Enter Account Holder first name" << endl; cin >> str; acc[no_of_accounts]->setFirstName(str); cout << "Enter Account Holder Last name" << endl; cin >> str; acc[no_of_accounts]->setLastName(str); cout << "Enter Account Initial balance" << endl; cin >> bal; acc[no_of_accounts]->setBalance(bal); no_of_accounts++; }

void EditBankaccount() { string ac; char response; double bal; cout << "Enter Bank Account number to be edited" << endl; cin >> ac; for (int i = 0; i < no_of_accounts; i++) { if (acc[i]->getAccountNumber() == ac) { while (1) { cout << " -----------------------" << endl; cout << "1. Edit First Name" << endl; cout << "2. Edit Last Name" << endl; cout << "3. Deposit Money" << endl; cout << "4. Withdraw" << endl; cout << "5. Exit" << endl; cin >> response; string str; switch (response) { case '1': cout << "Enter First Name" << endl; cin >> str; acc[i]->setFirstName(str); break; case '2': cout << "Enter Last Name" << endl; cin >> str; acc[i]->setLastName(str); break; case '3': cout << "Enter Deposit Amount" << endl; cin >> bal; acc[i]->setBalance(acc[i]->getBalance() + bal); cout << "Amount deposited" << endl;

break; case '4': cout << "Enter Withdrawal Amount" << endl; cin >> bal; if (acc[i]->getBalance() < bal) { cout << "Account balance is less than amount of withdrawal" << endl; } else { acc[i]->setBalance(acc[i]->getBalance() - bal); cout << "Amount withdrawn" << endl; } break; case '5': default: cout << "Bye" << endl; return; } } } } cout << "Account does not exist" << endl; }

int main() {

//Menu Option

int option; while (1) { cout << "------------------------------" << endl; cout << "Menu : Select an option" << endl; cout << "1. Display bank Accounts" << endl; cout << "2. Add New Bank Account" << endl; cout << "3. Edit existing Bank Account" << endl; cout << "4. Exit" << endl; cin >> option; switch (option) { case 1: displayBankAccounts(); break; case 2: AddNewAccount(); break; case 3: EditBankaccount(); break; case 4: default: cout << "Good Bye!" << endl; return 0; } }

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions