Question
How to move other function but main function to another header file and cpp file, and add an int id that will contain with individual
How to move other function but main function to another header file and cpp file, and add an int id that will contain with individual account information?
#include #include
using namespace std;
class Account { public: string name; double balance; Account(string n, double b) : name(n), balance(b) {} };
void displayAccountInfo(list
void addDeposit(list
int i = 0; list
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
int i = 0; list
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.emplace_back(name, balance); cout << "Account created successfully" << endl; }
void findAccountById(list
void removeAccount(list
void showTotalBalance(list
void addDividend(list
transform(accounts.begin(), accounts.end(), accounts.begin(), [dividend_percentage](auto& account) { account.balance += account.balance * (dividend_percentage / 100); return account; }); }
int main() { list
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
Get Instant Access to Expert-Tailored 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