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:
• 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.
-balance: double
+Account();
+Account(double);
+double getBalance();
+void deposit(double );
+void withdraw(double);
+void addInterest(double);
Account
Your class must work with the code given below and display the output .
240
450
Lab7.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<<"\n";
cout<
system("pause");
return 0;
}