For this lab you must write a complete class in C++. This will be a class named
ID: 651003 • Letter: F
Question
For this lab you must write a complete class in C++. This will be a class named BankAccount. This class must have the following private variables: 1. accountHolderName: string 2. balance: double 3. interestRate: double This class must have the following public constructor: 1. BancAccount(name : string, balance : double, rate : double) This class must have the following public member functions: 1. getAccountHolderName(): string a. returns the account holders name 2. getBalance(): double a. returns the current balance 3. getlnterestRate(): double a. returns the current interest rate 4. deposit(amount: double): void a. adds the amount to the balance 5. withdraw(amount: double): void a. subtracts the amount from the balance 6. applylnterest(): void a. adds interest (balance * interestRate) to the balance You must write the complete and correct BankAccount.h file that will contain the class declaration. You must write the complete and correct BankAccount.cpp file that will contain the implementation code.Explanation / Answer
//BankAccount.h file
#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H
#include<string>
//class bankaccount
class BankAccount
{
//all variables are private fields
private:
string accountHolderName;
double balance;
double interestRate;
//all methods are public fields
public:
//constructor
BankAccount(string name, double bal, double rate)
{
accountHolderName = name;
balance=bal;
interestRate = rate;
}
//to get accountholdername
string getAccountHolderName()
{
return accountHolderName;
}
//to get balance
double getBalance()
{
return balance;
}
//to get interest rate
double getInterestRate()
{
return interestRate;
}
//to add deposit amt
void deposit(double amt)
{
balance += amt;
}
//to withdraw amt
void withdraw(double amt)
{
balance -= amt;
}
//to apply interst to balance
void applyInterest()
{
balance += (balance * interestRate);
#endif /* BANKACCOUNT_H */
--------------------------------------------------------------------------------------------------
//BankAccount.cpp file
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.