These are the directions i was given.
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
Figure 1: The Account Class
Your class must work with the code given below and display the output .
240
450
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
Lab7.cpp (main)
#include<iostream>
using namespace std;
#include "Account.h"
int main()
{
Account a1;
Account a2(500);
a1.depost(200);
a2.withdraw(50);
a1.addInterest(0.2);
cout<<a1.getBalance();
cout<<"\n";
cout<<a2.getBalance();
system("pause");
return 0;
}
|