In: Computer Science
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate. f) A function named getMonthlyInterestRate() that returns the monthly interest rate. g) A function named withdraw(amount) that withdraws a specified amount from the account. h) A function named deposit(amount) that deposits a specified amount to the account. Implement the class. Write a test program that creates an Account object with an account ID of 1122, a balance of 20000, and an annual interest rate of 4.5%. Use the withdraw function to withdraw $2500, use the deposit function to deposit $3000, and print the balance, the monthly interest.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<iostream>
#include<iomanip>
using namespace std;
class Account{
private:
int id;
double balance;
double annualInterestRate;
public:
Account(){
id = 0; balance
= 0; annualInterestRate =0;
}
int getID() const{return id;}
double getBalance() const{return
balance;}
double getAnnualInterestRate()
const{return annualInterestRate;}
void setID(int id){this->id
=id;}
void setBalance(double bal);
void setAnnualInterestRate(double
rate);
double getMonthlyInterestRate()
const;
void withdraw(double amount);
void deposit(double amount);
double getMonthlyInterest()
const;
};
void Account::setBalance(double bal){
if(bal>0) balance = bal;
}
void Account::setAnnualInterestRate(double rate){
if(rate>0) annualInterestRate=rate;
}
double Account::getMonthlyInterestRate() const{
return annualInterestRate/12;
}
void Account::withdraw(double amount){
if(amount>0 && amount<balance) balance =
balance - amount;
else cout<<"Sorry! You dont have sufficient
funds.\n";
}
void Account::deposit(double amount){
if(amount>0) balance += amount;
}
double Account::getMonthlyInterest() const{
return
getMonthlyInterestRate()*getBalance()/100;
}
int main(){
Account myAccount;
myAccount.setID(1122);
myAccount.setBalance(20000);
myAccount.setAnnualInterestRate(4.5);
cout<<"Account Details:\n";
cout<<"Account ID: "<<
myAccount.getID()<<endl;
cout<<"Account Balance:
$"<<myAccount.getBalance()<<endl;
cout<<"Annual Interest Rate Pecentage:
"<<myAccount.getAnnualInterestRate()<<endl;
cout<<"Monthly Interest Rate Percentage:
"<<myAccount.getMonthlyInterestRate()<<endl;
cout<<"Monthly Interest Earned:
$"<<myAccount.getMonthlyInterest()<<endl;
cout<<"\nWithdrawing $4500 amount...\n\n";
myAccount.withdraw(4500);
cout<<"Account Balance:
$"<<myAccount.getBalance()<<endl;
cout<<"Monthly Interest Earned:
$"<<myAccount.getMonthlyInterest()<<endl;
cout<<"\nDepositing $3000 amount...\n\n";
myAccount.deposit(3000);
cout<<"Account Balance:
$"<<myAccount.getBalance()<<endl;
cout<<"Monthly Interest Earned:
$"<<myAccount.getMonthlyInterest()<<endl;
return 0;
}
======================================================================