Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CIS022_S2017_Assignment6 your name Select a location where you can find it later

ID: 3801219 • Letter: C

Question

CIS022_S2017_Assignment6 your name

Select a location where you can find it later

Choose the default application settings

2.

Insert the following function.

Open this file: CIS022_S2017_Assignment6.txt

Insert the function in your code module above the main() function.

The Files Info is Right here:

void CalculateMonthlyPayment(float LoanAmount, float AnnualInterestRate, int NumberOfPayments, int Payments)
{
   // calculates the monthly payment using
   // LoanAmount, AnnualInterestRate, and
   // NumberOfPayments

   float MonthlyInterestRate = AnnualInterestRate / 12 / 100;   // convert to monthly interest rate

   // P = L * i^n * i
   // -------------
   // i^n - 1
   Payments = (LoanAmount * pow(1 + MonthlyInterestRate, NumberOfPayments) *
       MonthlyInterestRate) /
       pow(1 + MonthlyInterestRate, NumberOfPayments) - 1;
}

1. Create a new Visual C++ Win32 Console application and name it:

CIS022_S2017_Assignment6 your name

Select a location where you can find it later

Choose the default application settings

2.

Insert the following function.

Open this file: CIS022_S2017_Assignment6.txt

Insert the function in your code module above the main() function.

The Files Info is Right here:

void CalculateMonthlyPayment(float LoanAmount, float AnnualInterestRate, int NumberOfPayments, int Payments)
{
   // calculates the monthly payment using
   // LoanAmount, AnnualInterestRate, and
   // NumberOfPayments

   float MonthlyInterestRate = AnnualInterestRate / 12 / 100;   // convert to monthly interest rate

   // P = L * i^n * i
   // -------------
   // i^n - 1
   Payments = (LoanAmount * pow(1 + MonthlyInterestRate, NumberOfPayments) *
       MonthlyInterestRate) /
       pow(1 + MonthlyInterestRate, NumberOfPayments) - 1;
}

3. Write code in your main function that will test the given function.

Hint: Hard code values for loan amount, interest rate, and number of payments at first. Use variable values after you get your program working. 4. Correct the function.

I'll help you out. There's 1 syntax error, one logic error in the calculation, and no trapping for out-of-bounds input.

Find them.

Fix them. 5. Insert your program documentation and code comments.

Just as you would do with any other project, insert your program documentation at the top and your code comments in your main() function.

Also, indicate with code comments where you made changes to the given function.

Explanation / Answer

#include <iostream>
#include <math.h>
void CalculateMonthlyPayment(float, float, int, float);
using namespace std;

int main()
{
cout << "Hello World" << endl;
int NumberOfPayments=2;
float Payments=5;
float LoanAmount=1000;
float AnnualInterestRate=40;
CalculateMonthlyPayment(LoanAmount,AnnualInterestRate,NumberOfPayments,Payments);

}
void CalculateMonthlyPayment(float LoanAmount, float AnnualInterestRate, int NumberOfPayments,float Payments)
{
// calculates the monthly payment using
// LoanAmount, AnnualInterestRate, and
// NumberOfPayments
float MonthlyInterestRate = (AnnualInterestRate / 12) / 100; // convert to monthly interest rate
cout<<MonthlyInterestRate<<" ";
// P = L * i^n * i
// -------------
// i^n - 1
cout<<" "<<(pow(1+ MonthlyInterestRate, NumberOfPayments));
Payments = (LoanAmount * (pow(1+ MonthlyInterestRate, NumberOfPayments)) *
MonthlyInterestRate) /
pow( MonthlyInterestRate, NumberOfPayments) - 1;
cout<<"Payment = "<<Payments;
}

/* The only change I did was to change the parameter from int to float. Coming to logical error it all depends on the formaula to be applied. It is not clear here which formula is applied here the only logical error that can occur is not placing the brackets at right places and the result coming to be wrong */

/*Evrything else is fine */