Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91668882
  • Price:- $65

Priced at Now at $65, Verified Solution

Have any Question?


Related Questions in C/C++

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As