Question: Modify the attached program to do the following: Rather than taking input from the keyboard it should get its inputs from a data file. Note:

Modify the attached program to do the following:

  • Rather than taking input from the keyboard it should get its inputs from a data file. Note: Since input is coming from the file, nothing needs to be displayed on the screen until the output is displayed.

#include #include // Access power function #include // Access manipulators /* ADD CODE */ // Access file i/o functions

using namespace std;

int main() { // Input variables float loanAmt; // Amount of loan float yearlyInt; // Yearly interest int numYears; // Number of years

// Local variables float monthlyInterest; // Monthly interest rate int numberOfPayments; // Total number of payments float payment; // Monthly payment /* ADD CODE */ // Link to input file /* ADD CODE */ // Input file name

// Prompt user for input file name /* ADD CODE */

// Open input file /* ADD CODE */

// Get first line of data from file /* ADD CODE */

// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* STILL NEEDED? */ cout << "Enter three values: " << " Loan amount, Yearly interest, and Number of years " << " Separate by spaces (Enter all 0's to quit): "; cin >> loanAmt >> yearlyInt >> numYears; cout << endl << endl;

// Loop until user enters 0... /* CHANGE CODE */ while (loanAmt != 0){

// Calculate values monthlyInterest = yearlyInt / 12; numberOfPayments = numYears * 12; payment = (loanAmt * pow(monthlyInterest + 1, numberOfPayments) * monthlyInterest)/(pow(monthlyInterest + 1, numberOfPayments) - 1);

// Send output to screen cout << fixed << setprecision(2) << "Loan amount: $" << loanAmt << endl; cout << fixed << setprecision(2) << "Interest rate: " << yearlyInt << endl; cout << "Years: " << numYears << endl << endl;

cout << "Your monthly payments are $" << payment << endl << endl << endl;

// Get next line of data from file /* ADD CODE */

// Prompt user for loanAmt, yearlyIn, numYears (Enter 0's to quit) /* STILL NEEDED? */ cout << "Enter the loan amount, yearly interest, and number of years separated by spaces (0's to quit): "; cin >> loanAmt >> yearlyInt >> numYears; cout << endl << endl; }

// Close file (necessary?) /* ADD CODE */

cout << "Good bye!" << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!