please code in c++ A bank account consists of an integer for the account number,
ID: 3889160 • Letter: P
Question
please code in c++
A bank account consists of an integer for the account number, a string for the account owner, a floating-point account balance, and a floating-point interest rate You can assume the constructor and standard "getter" and "setter" methods are already defined. Your job is to write the specification for two methods: 1. The Withdraw method subtracts a client-specified amount of money from the account, and indicates whether or not the request was successful (for example, if the client program tries to withdraw an amount greater than the account balance, it would not work). 2. The Addlnterest) method calculates the interest gained for the month and adds that amount to the account balance. The new account balance is returned to the calling code Your job is to write the specification for these two methods. You do not have to implement the actual logic of these methods, but you should supply a complete method signature and comments indicating purpose, precondition, postcondition, argument descriptions, and return value descriptionExplanation / Answer
please refer below code
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
//Base class with get() and set() function implemented
class account
{
private:
int acc_no;
string owner;
float balance;
float interest_rate;
public:
account() //constructor to reset all parameters
{
acc_no = 0;
owner = "";
balance = 0.0;
interest_rate = 0;
}
int get_acc_no() //get account number
{
return acc_no;
}
void set_acc_no(int val) //set account number
{
acc_no = val;
}
string get_owner() //get owner name
{
return owner;
}
void set_owner(string name) //set owner name
{
owner = name;
}
float get_balance() //get balance
{
return balance;
}
void set_balance(float val) //set balance
{
balance = val;
}
float get_interest() //get interest rate
{
return interest_rate;
}
void set_interest(float ir) //set interest rate
{
interest_rate = ir;
}
};
class client : public account
{
public:
bool withdraw(float amount) //withdraw amount
{
if(account::get_balance() < amount) //checking amount is less than balance in account if yes then successful else fail
return false;
else
{
account::set_balance(account::get_balance() - amount);
return true;
}
}
float AddInterest() //Add interest to balance
{
float inter,int_gained;
int_gained = account::get_balance() * account::get_interest() * 0.01; //calculating monthly interest balance * int_rate/100;
inter = account::get_balance() + int_gained;
account::set_balance(inter);
return account::get_balance(); //returning total balance after adding interest
}
};
int main()
{
int acc_no;
string owner_name;
float bal;
float ir;
float am_with;
client C;
cout<<"Setting initial Parameters of account"<<endl;
//We are taking initial parameters from user and do calculations based on that
cout<<"Enter account number : ";
cin>>acc_no;
C.account::set_acc_no(acc_no);
cout<<" Account Holder Name : ";
cin>>owner_name;
C.account::set_owner(owner_name);
cout<<" Enter Initial Balance : ";
cin>>bal;
C.account::set_balance(bal);
cout<<" Enter Interest Rate : ";
cin>>ir;
C.account::set_interest(ir);
cout<<" Enter amount to withdraw : ";
cin>>am_with;
if(C.withdraw(am_with))
cout<<"Withdraw Successful"<<endl;
else
cout<<"Insufficient balance"<<endl;
cout<<"New Account balance after adding interest : "<<C.AddInterest()<<endl;
return 0;
}
please refer below output
Setting initial Parameters of account
Enter account number : 12345
Account Holder Name : Chris
Enter Initial Balance : 2345.23
Enter Interest Rate : 4.6
Enter amount to withdraw : 459
Withdraw Successful
New Account balance after adding interest : 1973
Process returned 0 (0x0) execution time : 24.875 s
Press any key to continue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.