Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago