Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is my code, need help with error in c++ the error were: line 15 for_each' was not declared in this scope line 115 remove_if'

Here is my code, need help with error in c++ the error were:

line 15 for_each' was not declared in this scope

line 115 remove_if' was not declared in this scope;

line 132 'transform' was not declared in this scope

#include #include #include

using namespace std;

class Account { public: string name; double balance; Account(string n, double b) : name(n), balance(b) {} };

void displayAccountInfo(list& accounts) { for_each(accounts.begin(), accounts.end(), [](Account& account){ cout << "Name: " << account.name; cout << " Balance: " << account.balance << endl; }); }

void addDeposit(list& accounts) { int nameid; double deposit; cout << "Enter the account id: "; cin >> nameid; cout << "Enter the deposit amount: "; cin >> deposit;

int i = 0; list::iterator it;

for (it = accounts.begin(); it != accounts.end(); it++) { if (i == nameid) { it->balance += deposit; cout << "Deposit added successfully" << endl; return; } i++; } cout << "Account not found" << endl; }

void withdraw(list& accounts) { int nameid; double withdraw; cout << "Enter the the account id: "; cin >> nameid; cout << "Enter the withdrawal amount: "; cin >> withdraw;

int i = 0; list::iterator it;

for (it = accounts.begin(); it != accounts.end(); it++) { if (i == nameid) { if (it->balance < withdraw) { cout << "Insufficient funds" << endl; return; } it->balance -= withdraw; cout << "Withdrawal successful" << endl; return; } i++; } cout << "Account not found" << endl; }

void addAccount(list& accounts) { string name; double balance; cout << "Enter the the account id: "; cin >> name; cout << "Enter the initial balance: "; cin >> balance;

accounts.emplace_back(name, balance); cout << "Account created successfully" << endl; }

void findAccountById(list& accounts) { int id; cout << "Enter the the account id: "; cin >> id; int i = 0; list::iterator it; for (it = accounts.begin(); it != accounts.end(); it++) { if (i == id) { cout << "ID: " << i << endl; cout << "Name: " << it->name << endl; cout << "Balance: " << it->balance << endl; return; } i++; } cout << "Account not found" << endl; }

void removeAccount(list& accounts) { int id; cout << " Enter account ID to remove: "; cin >> id;

accounts.erase(remove_if(accounts.begin(), accounts.end(), [id](auto& account) { return id == account.get_id(); }), accounts.end()); }

void showTotalBalance(list accounts) { double total = accumulate(accounts.begin(), accounts.end(), 0.0f, [](auto& total, auto& account) { return total; }); cout << "Total in all accounts: $" << total << endl; }

void addDividend(list& accounts) { double dividend_percentage; cout << "Enter the dividend as a percentage: "; cin >> dividend_percentage;

transform(accounts.begin(), accounts.end(), accounts.begin(), [dividend_percentage](auto& account) { account.balance += account.balance * (dividend_percentage / 100); return account; }); }

int main() { list accounts;

while (true) { int choice; cout << "Main 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 << "4. Add new account" << endl; cout << "5. Find account by ID" << endl; cout << "6. Remove account" << endl; cout << "7. Show total balance for all accounts" << endl; cout << "8. Add a dividend to all accounts" << endl; cout << "Your choice: "; cin >> choice; if (choice == 0) { break; } else if (choice == 1) { if (accounts.empty()) { cout << "No accounts found" << endl; continue; } displayAccountInfo(accounts); } else if (choice == 2) { if (accounts.empty()) { cout << "No accounts found" << endl; continue; } addDeposit(accounts); } else if (choice == 3) { if (accounts.empty()) { cout << "No accounts found" << endl; continue; } withdraw(accounts); } else if (choice == 4) { addAccount(accounts); } else if (choice == 5) { if (accounts.empty()) { cout << "No accounts found" << endl; continue; } findAccountById(accounts); } else if (choice == 6) { removeAccount(accounts); } else if (choice == 7) { showTotalBalance(accounts); } else if (choice == 8) { addDividend(accounts); } else { cout << "Invalid choice. Please try again." << endl; } } 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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

Write formal and informal proposals.

Answered: 1 week ago

Question

Describe the components of a formal report.

Answered: 1 week ago

Question

Write formal and informal reports.

Answered: 1 week ago