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
|
//*************************************************************
//This program generates a table of factors used to
//compute monthly payment amounts for money borrowed.
//Again, this program does NOT compute monthly payment,
//only a table of factor values.
//*************************************************************
#include <iostream>//Header files
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
ofstream outfile;//File descriptor
//Prototypes
int openOutfile(); //Function opens the answer outfile
void getValues(double &mortgage, double &rateA, double &rateB, double &inc, int &yearA, int &yearB);//Function gets interest rate range, increment, and year range
void createTable(double &mortgage, double &rateA, double &rateB, double &inc, int &yearA, int &yearB);//Function creates a table of factors using user-provided values to compute
//Begin main
int main()
{
double mortgage, rateA, rateB, inc;//Declare variables
int yearA; int yearB;
openOutfile();
getValues(mortgage, rateA, rateB, inc, yearA, yearB);
cout << " Monthly Payment Factors Used in Computing Monthly Payments" << endl;
cout << " Interest Rates " << endl;
cout << endl;
cout << "Years" << endl;
createTable(mortgage, rateA, rateB, inc, yearA, yearB);
outfile.close();
return 0;
}
int openOutfile()
{
outfile.open("answers.out");//Open an outfile for answers
if( !outfile) //Check to see if outfile opens correctly
{
cout << "Error opening output file." << endl; //If it doesn't open correctly, display message
return 0; //and quit.
}
}
void getValues(double &mortgage, double &rateA, double &rateB, double &inc, int &yearA, int &yearB)
{
cout << "Enter amount to borrow." << endl;
cin >> mortgage;
cout << "Enter interest rate range (two values)," << endl
<< "and increment amount separated by spaces." << endl;
cin >> rateA >> rateB >> inc;
cout << "Enter the year range amount separated by a space." << endl
<< "ex. 1 15" << endl;
cin >> yearA >> yearB;
return;
}
void createTable(double &mortgage, double &rateA, double &rateB, double &inc, int &yearA, int &yearB)
{
while (rateA <= rateB)
{
cout << " " << setw(5) << showpoint << rateA ;
rateA = rateA + inc;
}
}
|