I am trying to set up a 12 month table summary in a bank account program. The problem I have is I am trying to figure out how to set it up correctly. Here is my class and application from the bank account:
Here's the class part:
class SavingsAccount
{
//Data declaration
private:
int accountNumber;
double balance;
double rate;
string depositChoice;
string withdrawalChoice;
double deposit;
double withdrawal;
double endBalance;
public:
//Methods declarations/prototypes
void setAccount(int,double,double);
double getBalance();
string deposChoice();
string withdrawChoice();
double depositBalance();
double withdrawalBalance();
double getEndingBalance();
};
//Methods implementation
//Constructor method: a special method used to
//initialize an object's state
//The constructor is automatically called and executed
//when the object is instantiated
void SavingsAccount::setAccount(int accNo, double startBalance, double startRate)
{
accountNumber = accNo;
balance = startBalance;
rate = startRate;
}
double SavingsAccount::getBalance()
{
cout << "\nThe current balance in your account is $"
<< balance << endl;
return balance;
}
string SavingsAccount::deposChoice()
{
cin.ignore();
cout << "\nWould you like to make a deposit(Y/N): ";
getline(cin, depositChoice);
return depositChoice;
}
double SavingsAccount::depositBalance()
{
if (depositChoice == "Y")
{
cout << "\nEnter amount to deposit: ";
cin >> deposit;
return deposit;
}
else if (depositChoice == "N")
{
cout << "\nOk no deposit I see!"
<< endl;
}
}
string SavingsAccount::withdrawChoice()
{
cin.ignore();
cout << "\nWould you like to make a withdrawal(Y/N): ";
getline(cin, withdrawalChoice);
return withdrawalChoice;
}
double SavingsAccount::withdrawalBalance()
{
if (withdrawalChoice == "Y")
{
cout << "\nEnter amount to withdrawal: ";
cin >> withdrawal;
return withdrawal;
}
else if (withdrawalChoice == "N")
{
cout << "\nOk no withdrawal I see!"
<< endl;
}
}
double SavingsAccount::getEndingBalance()
{
if (depositChoice == "Y" && withdrawalChoice == "Y")
{
endBalance = balance + deposit - withdrawal;
cout << "\nThe ending balance for your account is $"
<< endBalance << endl;
return endBalance;
}
else if (depositChoice == "Y" && withdrawalChoice == "N")
{
endBalance = balance + deposit;
cout << "\nThe ending balance for your account is $"
<< endBalance << endl;
return endBalance;
}
else if (depositChoice == "N" && withdrawalChoice == "Y")
{
endBalance = balance - withdrawal;
cout << "\nThe ending balance for your account is $"
<< endBalance << endl;
return endBalance;
}
else if (depositChoice == "N" && withdrawalChoice == "N")
{
endBalance = balance;
cout << "\nThe ending balance for your account is $"
<< endBalance << endl;
return endBalance;
}
}
Here's the cpp/application part:
#include <iostream>
#include<string>
#include <iomanip>
using namespace std;
#include "SavingsAccount.h"
//file is located in project directory
int main()
{
cout << "Welcome to the bank today!" << endl;
SavingsAccount newAccount;
newAccount.setAccount(111, 4000.0, .004);
newAccount.getBalance();
newAccount.deposChoice();
newAccount.depositBalance();
newAccount.withdrawChoice();
newAccount.withdrawalBalance();
newAccount.getEndingBalance();
cout << "\nMONTH START BALANCE INTEREST END BALANCE\n";
int month;
double interest = 0.0;
double endBalance = 0.0;
double rate = 0.0;
double newEndBalance = 0.0;
month = 1;
while (month <= 12)
{
interest = endBalance * rate;
newEndBalance = endBalance + interest;
cout << month << endBalance << interest << newEndBalance << endl;
month++;
}
cout << "\nThanks for stopping by the bank, have a nice day!\n" << endl;
return 0;
}//END MAIN
The output of the table is supposed to be like this:
Month Starting Interest Ending
# Balance Earned Balance
1 4000.00 16.00 4016.00
2 4016.00 16.06 4032.06
3 ... ... ...
4
5
6
7
8
9
10
11
12
The start balance of is table is the ending balance after I deposited/withdrew funds, the interest part I have to multiply the balance to the rate(.004) and the end balance is where I have to add the balance to interst.
The table part of it is the last part of the cpp part, I just wanted to know what to put there to make it come out correctly. Thanks greatly for the help.