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 122 123 124 125
|
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
class MortgagePayment
{
private:
double payment, loan, rate, total;
int years;
public:
void setLoan(double);
void setRate(double);
void setYears(int);
double getMonthlyPayment(double);
double getTotalPay();
};
//Set Methods
void MortgagePayment::setLoan(double L)
{
loan = L;
}
void MortgagePayment::setRate(double R)
{
rate = R;
}
void MortgagePayment::setYears(int Y)
{
years = Y;
}
double MortgagePayment::getMonthlyPayment(double Term)
{
return payment = ( loan * rate/12 * Term ) / (Term-1);
}
double MortgagePayment::getTotalPay()
{
return total = payment * years;
}
int main()
{
MortgagePayment mortgage1;
MortgagePayment mortgage2;
MortgagePayment mortgage3;
int choice;
double Term;
double LoanInput;
double RateInput;
double YearsInput;
//Front Intro Page
cout << "\n\n\t\t ********************************\n"
<< "\n\t\t\t CIS 180 Honors Work\n\n\t\t\t Mortgage Payment\n"
<< "\n\t\t\t\t By \n\n\t\t\t Trevor Davenport"
<< "\n\n\t\t ********************************\n\n\n"
<< "DESCRIPTION: This Program Demonstrates The Usage Of Classes,\n"
<< "\t Calculates The Total Monthly Payment For Mortgages,\n"
<< "\t Calculates The Total Amount Paid To The Banks,\n"
<< "\t And Returns The Above Mentioned In A Output Report.\n\n";
system("pause");
system("cls");
cout << "\n\nMORTGAGE PAYMENT OPTIONS:\n\n\tOption 1\n\n \tLoan Amount - $5,000.00\n\tRate - 5.0%\n\tYears - 5"
<< "\n\n\tOption 2\n\n \tLoan Amount - $10,000.00\n\tRate - 4.5%\n\tYears - 7"
<< "\n\n\tOption 3\n\n \tLoan Amount - $15,000.00\n\tRate - 6.5%\n\tYears - 9"
<< "\n\n\tWhich Payment Option Would You Prefer? ";
cin >> choice;
//Input Validation
while ( choice < 1 || choice > 3 )
{
cout << "\n\tError. Invalid Choice, Please Choose Again. ";
cin >> choice;
}
system("cls");
switch (choice)
{
case 1: mortgage1.setLoan(5000.00);
mortgage1.setRate(.05);
mortgage1.setYears(5);
Term = (1 + .05/12) * pow(12, 5); // Term = ( 1 + Rate / 12 ) ^ 12 * Years
break;
case 2: mortgage2.setLoan(10000.00);
mortgage2.setRate(.045);
mortgage2.setYears(7);
Term = (1 + .045/12) * pow(12, 7);
break;
case 3: mortgage3.setLoan(15000.00);
mortgage3.setRate(.065);
mortgage3.setYears(9);
Term = (1 + .065/12) * pow(12, 9);
break;
}
if ( choice == 1 )
{
cout << "\nMORTGAGE SUMMARY:\n\n\tLoan Amount - $5,000.00\n\tRate - 5.0%\n\tYears - 5\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage1.getMonthlyPayment(Term);
cout << "\nOTHER OPTIONS INCLUDED:\n\n\tLoan Amount - $10,000.00\n\tRate - 4.5%\n\tYears - 7\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage2.getMonthlyPayment(Term);
cout << "\nOTHER OPTIONS INCLUDED:\n\n\tLoan Amount - $15,000.00\n\tRate - 6.5%\n\tYears - 9\n\tMonthly Payment: " << fixed << setprecision(2) << mortgage3.getMonthlyPayment(Term);
}
if ( choice == 2 )
{
}
if ( choice == 3 )
{
}
}
|