Design a bank account class (IslanderAccount) that has the following attributes:
ID: 3740367 • Letter: D
Question
Design a bank account class (IslanderAccount) that has the following attributes: o Owner's name o Account number o Account balance and the following member functions: o a function that will create a new account o a function that will deposit funds into the account o a function that will withdraw funds from the account o a function that will return the current balance of the account o a function that will display the account information (owner's name, account number, and current balance) a function that will close the account mutator (setter) functions o o Notes: o If a withdraw transaction with an amount that is greater than the current balance is attempted, a $25 fee is deducted from the balance and the transaction is rejected. The user is informed with a displayed message. If the account balance becomes less than zero due to such fees, the account is closed. 12345 and the balance to zero. can be done to that account. o The default constructor initializes the owner's name to "Islander", account number to o When an account is closed, the account information is displayed and no further activities Write a program that demonstrates the IslanderAccount class. It should allow the user to create, deposit, withdraw, check balance, and/or close accounts.Explanation / Answer
#include<iostream>
#include<stdlib.h>
using namespace std;
class IslanderAccount
{
public:
string owner_name; // to store owner name
int acc_num; // to store account number
int acc_bal; // to store account balance
public :
IslanderAccount(string name,int acc,int bal)
{
// this is a perameterised constructor
// we are setting the values entered by the user;
//initially in the begining
owner_name=name;
acc_num=acc;
acc_bal=bal;
}
void getAccInfo()
{
// geting the account information
cout<<" Account Inormation ";
cout<<" Account holder name : "<<owner_name<<endl;
cout<<" Account Number :"<<acc_num<<endl;
cout<<" Account Balance :$"<<acc_bal<<endl;
}
void closeAccount()
{
// to close the account
// before closing the accout
// we have show the details of the account
getAccInfo();
cout<<" Account is Closed! ";
cout<<"Exit! ";
exit(0);// exiting from the overall program
}
void deposit()
{
// to dispoit the money into account
int amount;
cout<<"Enter Amount to deposit : $ ";
cin>>amount;
if(amount>0)
{
acc_bal=acc_bal+amount;// adding the newly entered amount to the previous account balance
cout<<"depositted Successfully! ";
cout<<"Your Final Amount is : $"<<acc_bal<<endl;
}
else
{
cout<<"Invalid Amount! ";
cout<<"Minimum deposit Amount should be $1 ";
}
}
void withdraw()
{
// to withdraw money
int amount;
cout<<"Enter Howmuch Amount you want to Withdraw : $ ";
cin>>amount;
if (amount>0)
{
// if amount is grater than 0 then only we can withdraw.
if(amount<=acc_bal)
{
// if entered amount is less than or exactly equal to the current acc_bal
// then onlly we can withdraw
acc_bal=acc_bal - amount;
cout<<"You have Successfully withdrawn an Amount of "<<amount<<endl;
cout<<"Remaining account balance : $"<<acc_bal<<endl;
}
else
{
// if insufficient balance
cout<<"You have Insufficient balance in your account. ";
acc_bal=acc_bal-25;
// the we fined them $25
if(acc_bal>0)
{
cout<<"We have Deducted $25 for your wrong attempt! ";
cout<<"Remaining account balance : $"<<acc_bal<<" ";
}
else if(acc_bal<0)
{
//after deducting $25 for the wrong attemp withdrawl
// then we closes his account
cout<<"We have Deducted $25 for your wrong attempt! ";
cout<<"Your Account balance becomes less than $0 ";
cout<<"We are Closing your account! ";
closeAccount();
}
}
}
else
{
cout<<"Invalid Amount! ";
cout<<"Minimum Withdraw Amount should be $1 ";
}
}
void getBalance()
{
// this is a mutator function to get the account balance (we wrote)
cout<<" Your Current Account Balance is : $"<<acc_bal<<endl;
}
};
void menu()
{
// this for the menu
// these + and --- are used for good design
cout<<"+---------------------------+ ";
cout<<"| Main Menu | ";
cout<<"+---------------------------+ ";
cout<<"| 1.Deposit | ";
cout<<"| 2.Withdraw | ";
cout<<"| 3.Get Balance | ";
cout<<"| 4.Display Account Info | ";
cout<<"| 5.Close Account & Exit | ";
cout<<"+---------------------------+ ";
}
int main()
{
// menu();
// if(1) return 0;
char wish;
cout<<"Would you like to create a new account (Y/N) ? ";
cin>>wish;
if (wish=='Y' || wish=='y')
{
// if the user wish to open an account it will enter here.
string name; // to take input from use his account name
int an; // acount number
int bal; // to store initial balance
cout<<"Enter Account holder first name: ";
cin>>name;
cout<<"Enter Account Number (Ex.123456): ";
cin>>an;
cout<<"Enter Initial Balance : $ ";
cin>>bal;
IslanderAccount newAcc(name,an,bal);//creating a new accounts with given names
int opt=0;
while(opt!=5)
{
menu();
cout<<"Choose your Option > ";
cin>>opt;// every time the use will choose one of the option we have in the main menu
switch(opt)
{
case 1:
//to deposit the money in to account
newAcc.deposit();
break;
case 2:
// to withdraw money
newAcc.withdraw();
break;
case 3:
// to get the current account balance
newAcc.getBalance();
break;
case 4:
// to know account info
newAcc.getAccInfo();
break;
case 5:
// to close account
newAcc.closeAccount();
break;
default:
// if the user enteres an invalid option
cout<<"Invalid Option! ";
break;
}
}
}
else{
cout<<"Exit!";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.