Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a c++ program with two arrays of size 5. One array will store the values of sum of selection and the second one will

write a c++ program with two arrays of size 5. One array will store the values of sum of selection and the second one will store the number of selections. Every element in the two arrays is calculated as follows: generate random numbers between 0 and 1 until their sum exceeds 1, then, store the sum as an element in the first array. The number of generated random numbers for that sum is stored in the second array. For example, if the program generated 0.3, 0.57 and 0.45 = 1.32 which exceeds 1, then the first element in the first array will be 1.32 (sum 2 of the three random numbers) and the first element in the second array will be 3 (number of generated random numbers until sum exceeds one.). The program will continue until it stores n elements in each array. For every element to be stored in the first array, display the generated random numbers as given in the sample output. Finally, the program displays the output of the two arrays

image text in transcribed

image text in transcribed

The aim of this question is to practice the usage of random numbers and arrays in C++. Basically, you are asked to write a C++ program as follows. Declare two arrays of size 5 . One array will store the values of sum of selection and the second one will store the number of selections. Every element in the two arrays is calculated as follows: generate random numbers between 0 and 1 until their sum exceeds 1 , then, store the sum as an element in the first array. The number of generated random numbers for that sum is stored in the second array. For example, if the program generated 0.3,0.57 and 0.45=1.32 which exceeds 1 , then the first element in the first array will be 1.32 (sum of the three random numbers) and the first element in the second array will be 3 (number of generated random numbers until sum exceeds one.). The program will continue until it stores n elements in each array. For every element to be stored in the first array, display the generated random numbers as given in the sample output. Finally, the program displays the output of the two arrays. Figure 1 shows a sample output of the program. Figure 1: Sample Output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions