Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 of 4 CpSc 1111 Lab 8 Arrays Overview This week, you will gain some experience with arrays, using loops to do the following declaring

image text in transcribed
image text in transcribed
image text in transcribed
1 of 4 CpSc 1111 Lab 8 Arrays Overview This week, you will gain some experience with arrays, using loops to do the following declaring and initializing arrays eprinting out the values in an array e scarching for values in an aray manipulating values in an array Background Information In lecture, you have leaned that arrays are data structures that store sets of same-type data items under a single name declare and initialize arrays, including using a declaration, You have seen how to values of an array. (Random number generators are discussed below.) random number generator to in You have also seen the use of loops to iterate through arrays to perform various tasks, such as finding the largest value in the array, swapping values of two elements in the array, ctc. Don't forget that the index values for the elements in the anray begin with 0 For this lab, you will use loops to initialize 2 arrays, print the values of cach array, search for a certain value in the array and to calculate the inner product of the 2 arrays Random Number Generators rand) and srand O The function rand() will generate a (pseudo) random number from 0 to RAND MAX, which is a constant defined in with a value of 32,767 You use the rand) function to return a value in a range by using module of the returned value by the range span+ nitial value of the range rand() % range-span + initial value where range span high low 1) For example, if you wanted 100 numbers from 0 to 99 If you wanted 100 numbers from 1 to 100 1985-2016 (nclusive) 10-30 (inclusive): rand () 100 (rand100) 1 (rand() 32) +1985 (rand 21) +10 But, using rand as explained above will produce the same setof "random" values every time you run it because it automatically seeds the random number generator with 1. You can seed the random number generator with the srand ) function using something other than 1The most common way to seed the random number generator is to use the time function, which is in the library file. This will seed the random number generator with the current time, which will be different every time you run the program, thus producing different sets of random values every time you run the program. The way to do this is by including the following line of code in your program, somewhere above the rand call: function srand (nt)te(0) Don't forget to Typically, you would only seed the random sumber generator once per every set of calls to cand #include both and at the top of your file

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

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

Understand human resource planning in an academic setting.

Answered: 1 week ago

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

1. Prepare a flowchart of Dr. Mahalees service encounters.

Answered: 1 week ago