nd( ) function from the library: rand( ) gives a random intege _MAX, where RAND_MAX is a predefined constant integer in C++. you use rand( ) make sure to include the empty braces (you will understane hen you learn about C++ functions). and(time(0)); statement at the beginning of main which requires adding the atement is needed if vou want the nrogram to oơive different random values for

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
The following functions/statements are useful to solve the probler:
• The pow function from the <math.h> library: e.g. pow(x.y) gives the value of x
• The rand( ) function from the <stdlib.h> library: rand( ) gives a random integer between 0 and
RAND_MAX, where RAND_MAX is a predefined constant integer in C++.
When you use rand( ) make sure to include the empty braces (you will understand what they mean
later when you learn about C++ functions).
The srand(time(0)); statement at the beginning of main which requires adding the <time.h> library.
This statement is needed if you want the program to give different random values for different runs.
The use of srand(time(0)) is optional; i.e. no grades will be deducted if you do not include it.
Transcribed Image Text:The following functions/statements are useful to solve the probler: • The pow function from the <math.h> library: e.g. pow(x.y) gives the value of x • The rand( ) function from the <stdlib.h> library: rand( ) gives a random integer between 0 and RAND_MAX, where RAND_MAX is a predefined constant integer in C++. When you use rand( ) make sure to include the empty braces (you will understand what they mean later when you learn about C++ functions). The srand(time(0)); statement at the beginning of main which requires adding the <time.h> library. This statement is needed if you want the program to give different random values for different runs. The use of srand(time(0)) is optional; i.e. no grades will be deducted if you do not include it.
Write a C++ program that performs the following (see the Appendix for useful functions):
(a) Prompt the user to enter two positive integers n and m (you are not required to handle the case when
n or m are not positive), and a real number z (z is real, i.e it can be a decimal and it can be negative).
Read the values entered by the user and store them in variables of appropriate data types.
(b) Ask the user to enter one of two choices:
- 'd' or 'D' for deterministic sum
- T' or 'R' for random product
o If the user's choice is a deterministic sum, then compute and print the following summation (where
n, m, and z are the values entered in part a):
m+n
k
det sum = 2(
(-1)*)
z x k
k=n
o Otherwise, if the choice is a random product, then compute and print the following random product
(where n, m, and z are the values entered in part a, and rg is a random decimal number between 0
and 1 inclusive):
m+n
[]a +r)
rand prod = z x
(1+
k=n
Note: Notice that rg depends on k, this means that you need to generate a new random
decimal in the range [0,1] for each k.
o If the user enters an invalid choice (any character other than 'd', 'D', 'r', or 'R'), print an error
message.
(c) Update the program to allow the user to repeat (enter new values of n, m, and z, and a new choice),
and display the new results for the new inputs. Your program will never stop (it will keep asking the
user for new input after each run)
Transcribed Image Text:Write a C++ program that performs the following (see the Appendix for useful functions): (a) Prompt the user to enter two positive integers n and m (you are not required to handle the case when n or m are not positive), and a real number z (z is real, i.e it can be a decimal and it can be negative). Read the values entered by the user and store them in variables of appropriate data types. (b) Ask the user to enter one of two choices: - 'd' or 'D' for deterministic sum - T' or 'R' for random product o If the user's choice is a deterministic sum, then compute and print the following summation (where n, m, and z are the values entered in part a): m+n k det sum = 2( (-1)*) z x k k=n o Otherwise, if the choice is a random product, then compute and print the following random product (where n, m, and z are the values entered in part a, and rg is a random decimal number between 0 and 1 inclusive): m+n []a +r) rand prod = z x (1+ k=n Note: Notice that rg depends on k, this means that you need to generate a new random decimal in the range [0,1] for each k. o If the user enters an invalid choice (any character other than 'd', 'D', 'r', or 'R'), print an error message. (c) Update the program to allow the user to repeat (enter new values of n, m, and z, and a new choice), and display the new results for the new inputs. Your program will never stop (it will keep asking the user for new input after each run)
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY