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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
Name:
Teacher:
Lab: 6
Date March 8, 2016
Purpose: To create a payment schedule each month. Also find out the payment needed each month
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
//Function InputData, Calculations, Output heading, output calculations
void inputData(double&, double&, double&, ofstream&);
double calcData(double&, double&, double&, double&, ifstream&);
void outputTHead(double, double, double, ofstream&);
void sigNature(ofstream&);
void calcdataOutput(double&, double&, double&, double&, ifstream&);
int main()
{
//Declare the variables to be input
double ccBal, intRate, percentMP;
//Declare variables to be calculated
double intperM, sumintPaid, minimum, updateBal;
//Create an ofstream to output data to ("lab6.txt")
ofstream outputFile;
outputFile.open("lab6.txt");
//CallInputData to Input Test Data (624, 24, 4)
inputData(ccBal, intRate, percentMP, outputFile);
//Now open the data that was output to lab6.txt and to be used to calculate
ifstream inputFile;
string data;
inputFile.open("lab6.txt");
cout << "Now opening Lab6.txt and reading data from it" << endl;
//If the file can't open send error
if (inputFile.fail())
{
cout << "Error opening file.";
}
//Call calcData to calculate the interestpermonth, interest paid, amount of payment due next month, and to update bal
calcData(updateBal, intperM, minimum, sumintPaid, inputFile);
//Call the function that output the table heading
outputTHead(ccBal, intRate, percentMP, outputFile);
//Call the function that outputs the calculation
calcdataOutput(updateBal, intperM, minimum, sumintPaid, inputFile);
//Call signature
sigNature(outputFile);
//Pause
system("pause");
}
void inputData(double& creditbal, double& interate, double& minimumpay, ofstream& outputFile)
{
//Ask for the input of credit balance, interest rate, and the minimumpay
cout << "What is your credit balance? ";
cin >> creditbal;
cout << "What is interest rate? ";
cin >> interate;
cout << "What is your minimum payment? ";
cin >> minimumpay;
//Output the Data into outputfile text called "Lab 6.txt"
outputFile << creditbal << endl;
outputFile << interate << endl;
outputFile << minimumpay << endl;
//Tell the user the data has been output in a text filed called "Lab 6.txt"
cout << "The data has been output into a text file called Lab 6.txt" << endl;
//Close the file
}
double calcData(double& updateBal, double& intperM, double& minimum, double& sumintPaid, ifstream& inputFile)
{
double credBal, APR, minPayPercent;
//Read the file
inputFile >> credBal;
inputFile >> APR;
inputFile >> minPayPercent;
//Change APR and minpaypercent into decimals and variable for balance and interest combined
double decAPR, minPayPercDec, balintComb, divideAPRyear;
divideAPRyear = APR / 12;
decAPR = divideAPRyear / 100;
minPayPercDec = minPayPercent / 100;
//Calculate for Bal, interestpermonth, minimum, and sum interest paid
intperM = credBal * decAPR;
balintComb = (credBal + intperM);
minimum = balintComb * minPayPercDec;
updateBal = balintComb - minimum;
sumintPaid = intperM;
return minimum;
}
void outputTHead(double balOwe, double APRaspercent, double percentminPay, ofstream& outputFile)
{
//
outputFile << "Balance Owing: $" << balOwe << endl;
outputFile << "APR as % " << APRaspercent << endl;
outputFile << "Percent for minimum payment as % " << percentminPay << endl;
}
void calcdataOutput(double& updateBal, double& intperM, double& minimum, double& sumintPaid, ifstream& inputFile)
{
for (double month = 0; updateBal > 0; month++)
{
cout << month << "\t" << updateBal << "\t" << intperM << "\t" << minimum << "\t" << sumintPaid << "\n";
calcData(updateBal, intperM, minimum, sumintPaid, inputFile);
}
}
void sigNature(ofstream& outputFile)
{
outputFile << "\n\nCreated by" << endl;
outputFile << "Date: March 9, 2016" << endl;
outputFile << "Teacher:" << endl;
}
|