Repository navigation
Expand file tree
/
Copy pathBanking.cpp
More file actions
81 lines (68 loc) · 2.9 KB
/
Copy pathBanking.cpp
File metadata and controls
81 lines (68 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Banking.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
Banking::Banking()
: totalBalance(0.0),
interestEarned(0.0),
yearlyInterest(0.0),
monthlyDeposit(0.0),
annualInterest(0.0),
years(0) {
}
Banking::Banking(double initialInvestment, double monthlyDepositAmt, double annualInterestRate, int numYears)
: totalBalance(initialInvestment),
interestEarned(0.0),
yearlyInterest(0.0),
monthlyDeposit(monthlyDepositAmt),
annualInterest(annualInterestRate),
years(numYears) {
}
// Setters
void Banking::setInitialInvestment(double amount) { totalBalance = amount; }
void Banking::setMonthlyDeposit(double amount) { monthlyDeposit = amount; }
void Banking::setInterestRate(double rate) { annualInterest = rate; }
void Banking::setYears(int numYears) { years = numYears; }
// Getters
double Banking::getInitialInvestment() const { return totalBalance; }
double Banking::getMonthlyDeposit() const { return monthlyDeposit; }
double Banking::getInterestRate() const { return annualInterest; }
int Banking::getYears() const { return years; }
// Report: Without monthly deposit
double Banking::balanceWithoutMonthly(double initialInvestment, double annualInterestRate, int numYears) {
totalBalance = initialInvestment;
cout << "\n Balance and Interest Without Additional Monthly Deposits\n";
cout << string(66, '=') << "\n";
cout << "Year Year End Balance Year End Earned Interest\n";
cout << string(66, '-') << "\n";
for (int i = 0; i < numYears; ++i) {
interestEarned = totalBalance * (annualInterestRate / 100.0);
totalBalance += interestEarned;
cout << " " << left << setw(5) << (i + 1)
<< "\t\t$ " << fixed << setprecision(2) << totalBalance
<< "\t\t\t\t$" << interestEarned << "\n";
}
return totalBalance;
}
// Report: With monthly deposit
double Banking::balanceWithMonthly(double initialInvestment, double monthlyDepositAmt, double annualInterestRate, int numYears) {
totalBalance = initialInvestment;
cout << "\n Balance and Interest With Additional Monthly Deposits\n";
cout << string(66, '=') << "\n";
cout << "Year Year End Balance Year End Earned Interest\n";
cout << string(66, '-') << "\n";
for (int i = 0; i < numYears; ++i) {
yearlyInterest = 0.0;
for (int j = 0; j < 12; ++j) {
double monthlyRate = (annualInterestRate / 100.0) / 12.0;
interestEarned = (totalBalance + monthlyDepositAmt) * monthlyRate;
yearlyInterest += interestEarned;
totalBalance += monthlyDepositAmt + interestEarned;
}
cout << " " << left << setw(5) << (i + 1)
<< "\t\t$" << fixed << setprecision(2) << totalBalance
<< "\t\t\t\t$" << yearlyInterest << "\n";
}
return totalBalance;
}