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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include "Finance.h"
#include <iomanip>
using namespace std;
double Finance::MaturityCalc (double invest, float interestR, float years, int compound)
{
double interestT;
double epon;
interestT = (1+((interestR/100) / compound)); // =(1+P/M)
epon = (years * compound); //^(Y*M)
double result = invest * pow (interestT, epon); //Finally, multiply the investment into the total interest
return result;
}
int Finance::maturitydriver()
{
double invest;
float interestR;
float years;
int compound;
double maturity;
cout << "This program will calcuate a maturity. Please enter the following: \n";
//ask user for input
cout << "\nInital investment: ";
cin >> invest;
cout << "\n";
cout << "Interest rate, in percentage: ";
cin >> interestR;
cout << "\n";
cout << "Total years of maturity: ";
cin >> years;
cout << "\n";
cout << "Compound, number of times interest is applied: ";
cin >> compound;
cout << "\n";
maturity = MaturityCalc(invest, interestR, years, compound);
cout << "Your maturity is: " << maturity << "\n";
system ("pause");
return 0;
}
double Finance::loanPay (int loan, float rate, int payment)
{
float baseLoan = 0;
double numer = 0;
double denom = 0;
double resultB = 0;
double resultF = 0;
double resultT = 0;
baseLoan = (1 + (rate/1200));
resultB = pow ((double) baseLoan, (double) payment);
numer = ((double) rate/1200) * resultB;
denom = resultB - 1;
resultF = numer / denom;
resultT = resultF * loan;
return resultT;
}
int Finance::loanDriver()
{
cout << "This program will calculate your monthly loan payments,\n";
cout << "please enter the following: \n";
int loan, payment = 0; //L and N, Loan amount and number of payments
float rate = 0; //R, interest rate
double getLoan = 0; //calls getloan
cout << "\nLoan amount: ";
cin >> loan;
cout << "\n";
cout << "Interest Rate, in percentage: ";
cin >> rate;
cout << "\n";
cout << "Number of payments: ";
cin >> payment;
cout << "\n";
getLoan = loanPay(loan,rate,payment);
cout << "Your monthly loan payment is: " << getLoan << "\n"; //display results
system ("pause");
return 0;
};
int swapDriver ()
{
int x;
int y;
cout << "\nPlease enter x: ";
cin >> x;
cout << "\nPlease enter y: ";
cin >> y;
swap (x, y);
cout << "\n After swap: Here is x: "<< x << " and y: " << y;
system ("pause");
return 0;
}
void swap (int x, int y)
{
int temp = x;
x = y;
y = temp;
return ;
}
|