//-------------------------------------------------------------------- //Programmed by: Mark Cruz // Date: 11/12/02 // Laboratory 6, Prelab Ex. 3, Application test testloan.cpp // //-------------------------------------------------------------------- // Displays a loan schedule for a fully amortized loan. #include #include #include #include // Function prototypes double monthlyPayment ( double principal, double annualRate, int numYears ); void loanSchedule ( double principal, double annualRate, int numYears ); void main () { double principal, // Amount borrowed (in dollars) interestRate; // Annual interest rate (as a % of 1.0) int numYears; // Length of the loan (in years) // Prompt the user and read in the amount borrowed, interest // rate, and length of the loan. cout << endl << "Enter the amount borrowed: "; cin >> principal; cout << "Enter the annual interest rate (as a % of 1.0): "; cin >> interestRate; cout << "Enter the length of the loan (in years): "; cin >> numYears; // Output the monthly payment. cout << "Monthly payment : $" << monthlyPayment(principal,interestRate,numYears) << endl; // Output the loan schedule. loanSchedule(principal,interestRate,numYears); } //-------------------------------------------------------------------- // Insert your function implementations here. //-------------------------------------------------------------------- double monthlyPayment ( double principal, double annualRate, int numYears ) { double months = numYears*12; double mpr = annualRate/12; cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout << setprecision (2); double monthlyPayment = mpr*((principal)/(1-(1/(pow (1 + mpr,months))))); return monthlyPayment; } void loanSchedule (double principal, double annualRate, int numYears ) { int month = 0; double mpr, ipay, balance, mp, ppay; ofstream outfile ("loan.txt"); mpr = annualRate/12; mp = monthlyPayment(principal,annualRate,numYears); outfile << "Month" << setw(20) << "Interest Paid" << setw(25) << "Principal Paid" << setw(25) << "Remaining Balance" <