-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserDataCalculations.cpp
101 lines (78 loc) · 3.71 KB
/
UserDataCalculations.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
using namespace std;
#include "UserDataCalculations.h"
void UserDataCalculations::dataWithoutDeposits(InvestmentData t_userInvestment) {
/* first display without monthly deposits */
// initializing local vars with the user data
double initialInvestment = t_userInvestment.getInitialInvestment();
int years = t_userInvestment.getNumOfYears();
// data for proper message alignment
int screenWidth = 80;
string balanceMsg = "Balance & Interest Without Additional Monthly Deposits";
int centerScreen = balanceMsg.length() / 2;
int halfWidth = screenWidth / 2;
int sizeToCenter = halfWidth + centerScreen;
cout << endl;
/* main header for data */
cout << setfill(' ') << setw(sizeToCenter) << balanceMsg << setfill(' ') << setw(sizeToCenter) << endl;
cout << setfill('=') << setw(80) << '=' << endl;
cout << setfill(' ') << left << setw(26) << "Year" << "Year End Earned Interest" << right << setw(30) << "Year End Balance" << endl;
cout << setfill('-') << setw(80) << '-' << endl;
// adds the initial amount to the total
t_userInvestment.setTotalWithoutDeposits(initialInvestment);
double interestYTD = 0;
unsigned int yearCount, monthCount;
// runs calculations
for (yearCount = 1; yearCount <= years; yearCount++) {
for (monthCount = 1; monthCount <= 12; monthCount++) {
interestYTD += t_userInvestment.calcInterestWithoutDeposits();
}
t_userInvestment.setTotalWithoutDeposits(interestYTD); // adds total interest from the year to main total
cout << setfill(' ') << left << setw(30) << yearCount;
cout << "$" << fixed << setprecision(2) << interestYTD;
cout << right << setw(35) << "$" << fixed << setprecision(2) << t_userInvestment.getTotalWithoutDeposits() << endl;
interestYTD = 0; // reset
}
}
void UserDataCalculations::dataWithDeposits(InvestmentData t_userInvestment) {
/* second display without monthly deposits */
// initializing local vars with the user data
double initialInvestment = t_userInvestment.getInitialInvestment();
double monthlyDeposit = t_userInvestment.getMonthlyDeposit();
int years = t_userInvestment.getNumOfYears();
string balanceMsg = "Balance & Interest With Additional Monthly Deposits";
int screenWidth = 80;
// data for proper message alignment
int centerScreen = balanceMsg.length() / 2;
int halfWidth = screenWidth / 2;
int sizeToCenter = halfWidth + centerScreen;
cout << endl;
/* main header for data */
cout << setfill(' ') << setw(sizeToCenter) << balanceMsg << setfill(' ') << setw(sizeToCenter) << endl;
cout << setfill('=') << setw(80) << '=' << endl;
cout << setfill(' ') << left << setw(26) << "Year" << "Year End Earned Interest" << right << setw(30) << "Year End Balance" << endl;
cout << setfill('-') << setw(80) << '-' << endl;
// adds the initial amount to the total
t_userInvestment.setTotalWithDeposits(initialInvestment);
// reset interest totals
double interestYTD = 0;
unsigned int yearCount, monthCount;
// runs the calculations
for (yearCount = 1; yearCount <= years; yearCount++) {
for (monthCount = 1; monthCount <= 12; monthCount++) {
t_userInvestment.setTotalWithDeposits(monthlyDeposit); // adds the monthly deposit to total
double interest = t_userInvestment.calcInterestWithDeposits(); // gets interest calculation
t_userInvestment.setTotalWithDeposits(interest); // adds the new interest to total
interestYTD += interest;
}
// adds total interest from the year to main total
cout << setfill(' ') << left << setw(26) << yearCount;
cout << "$" << fixed << setw(37) << setprecision(2) << interestYTD;
cout << left << "$" << fixed << setprecision(2) << t_userInvestment.getTotalWithDeposits() << endl;
interestYTD = 0; // reset
}
}
// end code