Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. =Design and code a generic value returning function named payment. The function is generic in the sense that it may be used in any program to calculate any type of fixed loan payment. The function will calculate and return the payment amount as a double.
  2.  
  3. The function receives four value parameters as described below. Code parameters in the order shown below which is similar to the Excel pmt function
  4.  
  5. a. annual interest rate stored as a double, eg: 7.25% Note: You will need to convert from percentage to proper mathematical decimal value inside the function.
  6. b. number of years financed stored as a double, eg: 3.5 years
  7. c. number of payment periods per year stored as an integer value. eg: payments may be monthly (12), quarterly (4) , semiannually (2), etc.
  8. d. amount borrowed – the principal amount of the loan in US currency stored as a double
  9.  
  10. Use the following formula for calculating the payment amount. Note that inside the function you will need to calculate nper and rate as well as the payment. Use the pow function to calculate (1+rate)nper in the formula (see details below). Use lower case and camel-case for parameter and variable names.
  11.  
  12. payment = rate * (1+rate)nper * loan /(1+rate)nper- 1
  13.  
  14.  
  15. where:
  16. rate is the fixed periodic interest rate calculated by dividing the annual interest rate by the number of pay periods per year (Note: must convert the annual interest rate to proper mathematical percentage, eg. 9% as 0.09)
  17.  
  18. nper is the total number of payments, called the loan’s term: calculated by multiplying the number of years financed by the number of pay periods per year
  19.  
  20. loan is the amount borrowed, called the loan’s principal
  21.  
  22. Use a variable to store the results of the pow function used to calculate (1+rate)nper. Since this expression is required twice in the above formula you can avoid function call overhead by calling the function once, storing the results and using the stored result twice in the formula. See Math Library Functions in Chap 3 pg. 131 and Appendix F pg. 1324. Include cmath header file.
  23.  
  24. Note: The annual interest rate can be 0.0% as on a new car loan; if so how is the payment amount calculated? Hint: You will need to add an if statement for this special case where the payment amount is the total loan amount divided by the total number of payments
  25.  
  26.  
  27. 2. Driver Programs: Chapter 6, pg. 413-415. Design a driver program (a main function) to test the above function with calls containing only literal arguments. Note that there are NO variables required in the main function.
  28. See the example program entitled Pr6-30.cpp included in this assignment’s box in Canvas. It is an example of bottom up design where you create a main program, called a driver, to specifically test a function. This example test three different calls to the showFees function.
  29. This approach is an easier method of testing and debugging a function since you don't have to go through the tedious task of typing input data values for each test run. We will do that in another assignment
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement