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
|
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include "HW3.h"
using namespace std;
int main() {
LoanData obj;
return 0;
}
class LoanData
{
double beginningBalance, Payment, interestPaid, principlePaid, endingBalance;
private:
double Bal = 100000;
double n = 30;
double i = 6;
double A;
double p = Bal;
public:
LoanData(double p, double n, double i);
void MakePayment(double pay);
void PrintAmortizationSchedule() {
printf("%lf %lf %lf %lf", beginningBalance, interestPaid, principlePaid, endingBalance);
}
void PrintPayOffTimeReport(double p, double i) {
printf("%lf %lf", n, A);
}
};
LoanData::LoanData(double p, double n, double i)
{
i = (i / 100) / 12;
n = n * 12;
A = p * (i * (pow((1 + i), n)) / (pow((1 + i), n) - 1));
Bal = p;
}
void LoanData::MakePayment(double pay)
{
Bal = (i + 1)*Bal - pay;
}
void LoanData::PrintAmortizationSchedule()
{
while (Bal > 0) {
double p = Bal;
if ((i + 1)*p > A) {
Payment = A;
}
else {
Payment = (i + 1)*p;
}
interestPaid = i*p;
principlePaid = A - i*p;
endingBalance = (i + 1)*p - A;
beginningBalance = endingBalance;
}
}
void LoanData::PrintPayOffTimeReport(double p, double i)
{
for (n = 1; n < 50; n++)
{
A = p * (i * (pow((1 + i), n)) / (pow((1 + i), n) - 1));
}
}
|