In: Computer Science
(In C++)
Bank Account Program
Create an Account Class
Create a Menu Class
Create a main() function to coordinate the execution of the program.
We will need methods:
Method for Depositing values into the account.
What type of method will it be?
Method for Withdrawing values from the account.
What type of method will it be?
Method to output the balance of the account.
What type of method will it be?
Method that will output all deposits made to the account.
Method that will output all withdraws made from the account.
**************************************
* Bank Account Program: *
* Enter # to run program or Quit *
* 1) Make a Deposit *
* 2) Make a Withdrawal *
* 3) Output balance *
* 4) Output all deposits *
* 5) Output all withdrawals *
* 6) Quit *
**************************************
Attach Snipping Photo of Source Code and Output
Make sure to attach pictures of each menu option working.
if you have any Query comment Down Below
CODE:
#include <iostream>
#include <vector>
using namespace std;
class Account {
int balance;
vector<int> withdrawHistoryAmount;
vector<int> depositHistoryAmount;
public:
Account(){
balance=0;
}
Account(int bal){
balance=bal;
}
void deposit()
{
int dep;
cout<<"\n Enter Deposit Amount = ";
cin>>dep;
if(dep>0){
balance+=dep;
depositHistoryAmount.push_back(dep);
}
}
void withdraw() //withdrawing an amount
{
int withdrawAm;
cout<<"\n Enter Withdraw Amount = ";
cin>>withdrawAm;
if(withdrawAm>balance)
cout<<"\n Cannot Withdraw Amount";
balance-=withdrawAm;
withdrawHistoryAmount.push_back(withdrawAm);
}
void outputBalance(){
cout<<"Total Amount : "<<balance<<endl;
}
void allDeposit(){
if(depositHistoryAmount.size()>0){
cout<<"All Deposit are :\n";
for (auto i = depositHistoryAmount.begin(); i !=
depositHistoryAmount.end(); ++i)
cout << *i << " ";
}
else{
cout<<"There is not Deposit History\n";
}
cout<<"\n";
}
void allWithdraw(){
if(withdrawHistoryAmount.size()>0){
cout<<"All allWithdraw are :\n";
for (auto i = withdrawHistoryAmount.begin(); i !=
withdrawHistoryAmount.end(); ++i)
cout << *i << " ";
}
else{
cout<<"There is not withdraw History\n";
}
cout<<"\n";
}
};
void menu(){
cout<<"**************************************\n";
cout<<"* Bank Account Program: *\n";
cout<<"* Enter # to run program or Quit *\n";
cout<<"* 1) Make a Deposit * \n";
cout<<"* 2) Make a Withdrawal * \n";
cout<<"* 3) Output balance *\n";
cout<<"* 4) Output all deposits *\n";
cout<<"* 5) Output all withdrawals *\n";
cout<<"* 6) Quit *\n";
cout<<"**************************************\n";
}
int main() {
char choice;
Account a;
menu();
cin>>choice;
if(choice=='#'){
while(choice!='6'){
switch(choice){
case '1':
a.deposit();
break;
case '2':
a.withdraw();
break;
case '3':
a.outputBalance();
break;
case '4':
a.allDeposit();
break;
case '5':
a.allWithdraw();
break;
}
menu();
cin>>choice;
}
}
cout<<"Thanks FOr using\n";
}
SS: