Home loan amortization develop and test a program that


Further basics of C++ programming

Purpose: This homework involves some further basics of C++ programming, specifically loops. You will also get to work with random numbers again, which are important in formulating solutions to a multitude of problems in the scientific community and elsewhere (see the motivation for the introduction of random number generation in the last homework assignment (i.e., HW2)).

Instructions: The instructions are similar to previous homework's: This is an individual, not collaborative assignment; remember to be careful with naming rules; etc. See the HW 1 or HW2 descriptions for more details. Problem A: Tossing a Fair DieWrite a C++ program that simulates tossing a fair six-sided die. Your program should do the following:

1. Ask the user to input a random seed (of type int), and call srand with thenumber that is input as its argument. Thus, right after the variable declarations inyour program, you should have the lines:

cout << "Input the random seed: ";

cin >> seed;

srand(seed);

2.Use the cstdlib function rand() to generate a random number between 1 and 6.

Note that the number 1 corresponds to one dot on the side of a die; the number 2 corresponds to two dots on the side of a die, and so on for the numbers 2, 3, 4, 5, and 6, where each number represents the number of dots on the side of a six-sided die. All possibilities (one dot through six dots) should be equally likely to occur when a die is rolled. Repeat this process 100 times, and keep a count of the number of times each dot occurs when the die is rolled.

3. Repeat Step 2 (i.e., generate another 100 random numbers) and count the number of times each number of dots surfaces on the die.

4. Print out the results, that is, the counts for each time each side of the die was rolled, and the average value for the 100 rolls of the die for each set.

5. Continue until the program user chooses to exit by inputting a character other than ‘y'

Below is an example run of the program.

Input the random seed: 35

First SetSecond Set

one1816

two1113

three2113

four2525

five1321

six1212

Set 1 Avg.Set 2 Avg.

3.43.58

Would you like to continue (Enter y or n): y

First SetSecond Set

one2210

two1220

three1725

four1319

five166

six2020

Set 1 Avg.Set 2 Avg.

3.493.51

Would you like to continue? (Enter y or n): n Be sure to include a continuation loop in your program (as indicated in step 5 above and demonstrated in the example above). Hint: The switch statement might be helpful in formulating your program.

Problem B: Home Loan Amortization Develop and test a program that calculates the monthly payments for a loan amount and a term (number of years) input by the user. Once the loan amount and term are obtained from the user, the program should compute and display the monthly payment for a range of interest rates from 3% to 18%. The formula for determining this is A/D, where A is the original loan amount (the loan amount entered by the user) and D is the discount factor. The discount factor is calculated as follows:

D = ((1 + r)n-1) / r(1 + r)n

Where n is the total number of payments (assume that one payment is made each month, and thus n is equal to 12 times the number of years of the loan), and r is the interest rate expressed in decimal form (e.g., 0.05 for a 5% interest rate) divided by 12.

A monthly payment table should be generated as shown in the outline of an example run below:

Enter Loan Amount: 350000

Enter Term for Loan (in Years): 30

Interest RateMonthly Payment

3% 1475.61

4% 1670.95

5% 1878.88

6% 2098.43

..

. .

. .

18% 5274.80

Would you like to continue? (Enter y or n): n Note that your program should include a continuation loop that will enable to the user to enter a new loan amount and new term and generate a new table based on the new amount and term without exiting the program (in a manner similar to Problem A) Test your program a variety of times to make sure its answers are correct. You can check your results with an online mortgage calculator.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Home loan amortization develop and test a program that
Reference No:- TGS01280514

Now Priced at $65 (50% Discount)

Recommended (92%)

Rated (4.4/5)