Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The exercise for this week is to write a class that simulates managing a simple

ID: 3672204 • Letter: T

Question

The exercise for this week is to write a class that simulates managing a simple bank account. The account is created with an initial balance. It is possible to deposit and withdraw funds, to add interest, and to find out the current balance. This should be implemented in class named Account that includes:

Please Submit Your Account.h, Account.cpp and Lab7.cpp

A default constructor that sets the initial balance to zero.

A constructor that accepts the initial balance as a parameter.

A function getBalance that returns the current balance.

A method deposit for depositing a specified amount.

A method withdraw for withdrawing a specified amount.

A method addInterest for adding interest to the account.

The addInterest method takes the interest rate as a parameter and changes the balance in the account to balance*(1+interestRate).

The UML diagram for the Account class is shown in figure 1.

-----------------------------------------------------

Account

-balance: double

+Account();

+Account(double);

+double getBalance();

+void deposit(double );

+void withdraw(double);

+void addInterest(double);

----------------------------------------------------

Your class must work with the code given below and display the output .

240

450

Lab1.cpp (main)

#include

using namespace std;

#include "Account.h"

int main()

{

Account a1;

Account a2(500);

a1.depost(200);

a2.withdraw(50);

a1.addInterest(0.2);

cout<

cout<<" ";

cout<

system(pause);

return 0;

}

Please Submit Your Account.h, Account.cpp and Lab7.cpp

// Lab7.cpp

#include<iostream>
using namespace std;
#include "Account.h"
int main()
{
   Account   a1;
   Account   a2(500);
   a1.deposit(200);
   a2.withdraw(50);
   a1.addInterest(0.2);
   cout << a1.getBalance();
   cout << " ";
   cout << a2.getBalance();
   system("pause");
   return 0;
}

//Account.cpp

#include "Account.h"

Account::Account() :balance(0)
{

}
Account::Account(double startingBal) : balance(startingBal)
{

}

double Account :: getBalance() const
{
   return balance;
}
void Account :: deposit(double amount)
{
   balance += amount;
}
void Account :: withdraw(double amount)
{
   balance -= amount;  
}
void Account :: addInterest(double interestRate)
{
   balance = balance *(1 + interestRate);
}

// Account.h

using namespace std;
class Account
{
private:
   double balance;

public:
   Account();
   Account(double startingBal);

   double getBalance() const;
   void deposit(double amount);

   void withdraw(double amount);
   void addInterest(double interestRate);
};

Explanation / Answer



Account.cpp



Edit & Run

   #ifndef ACCOUNT_H  #define ACCOUNT_H    class Account  {  private:          double balance = 0;    public:          Account();          Account(double startingBal);          double getBalance() const;          void deposit(double amount);          void withdraw(double amount);          void addInterest(double interestRate);  };  #endif //ACCOUNT_H    
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote