Please Please Please Read the instructions and do everything listed there. if you no going to read the instructions and I received bad Credit I will do Bad Rating.
Lab #11:
Write a program that will do the following:
In main, declare an array of size 20 and name it "randomArray." Use the function in step 2 to fill the array. Use the function in step 3 to print the array.
Create a function that generates 20 random integers with a range of 1 to 10 and places them into an array. Re-cycle the functions from Lab 10 where appropriate.
Make this a function.
There will be two arguments in the parameter list of this function: an array and the size of the array.
Within the function and the function prototype name the array: intArray.
Within the function and the function prototype name the size of the array: size.
The data type of the function will be void since the array will be sent back through the parameter list.
Bring in the function that generates and returns a random number that you created from the previous module
.
Call that function
from this within the loop that adds random numbers to the array.
Display the contents of the array. Re-cycle the function that prints out the contents of an integer array from Lab 10.
Make this a function.
There will be two arguments in the parameter list of this function: an array and the size of the array.
Within the function and the function prototype name the array: intArray.
Within the function and the function prototype name the size of the array: size.
The data type of the function will be void since the array will be sent back through the parameter list.
From main, generate one more random number (also from 1 to 10) from the random number function. Do not put this in an array. This is a stand alone variable that contains one random number.
Search though the array and count how many times the extra random number occurs. It is possible that the extra random number may occur more than once or not at all.
Output:
• Display the entire array.
• Display the extra random number.
• Depending upon the result of your search, display one of the following:
– How many times the random number occurs.
– That the random number did not occur at all.
Also include:
Use a sentinel driven outer While Loop to repeat the task
Ask the User if they wish to generate a new set of random numbers
Clear the previous list of numbers from the output screen before displaying the new set.
NOTE 1: Other than the prompt to repeat the task, there is no input from the User in this program.
NOTE 2: This program will have 3 functions:
The function that fills the array with random numbers.
The function that generates one random number at a time (re-use the one from Lab 10).
The function that prints out an array of integers (re-use the one from Lab 10).
======================= Please Read ======================
Searching Through Arrays
Now t.
Please Please Please Read the instructions and do everything li.docx
1. Please Please Please Read the instructions and do everything
listed there. if you no going to read the instructions and I
received bad Credit I will do Bad Rating.
Lab #11:
Write a program that will do the following:
In main, declare an array of size 20 and name it
"randomArray." Use the function in step 2 to fill the array.
Use the function in step 3 to print the array.
Create a function that generates 20 random integers with a
range of 1 to 10 and places them into an array. Re-cycle the
functions from Lab 10 where appropriate.
Make this a function.
There will be two arguments in the parameter list of this
function: an array and the size of the array.
Within the function and the function prototype name the array:
intArray.
Within the function and the function prototype name the size of
the array: size.
2. The data type of the function will be void since the array will be
sent back through the parameter list.
Bring in the function that generates and returns a random
number that you created from the previous module
.
Call that function
from this within the loop that adds random numbers to the
array.
Display the contents of the array. Re-cycle the function that
prints out the contents of an integer array from Lab 10.
Make this a function.
There will be two arguments in the parameter list of this
function: an array and the size of the array.
Within the function and the function prototype name the array:
intArray.
Within the function and the function prototype name the size of
the array: size.
The data type of the function will be void since the array will be
sent back through the parameter list.
From main, generate one more random number (also from 1 to
3. 10) from the random number function. Do not put this in an
array. This is a stand alone variable that contains one random
number.
Search though the array and count how many times the extra
random number occurs. It is possible that the extra random
number may occur more than once or not at all.
Output:
• Display the entire array.
• Display the extra random number.
• Depending upon the result of your search, display one of the
following:
– How many times the random number occurs.
– That the random number did not occur at all.
Also include:
Use a sentinel driven outer While Loop to repeat the task
Ask the User if they wish to generate a new set of random
numbers
Clear the previous list of numbers from the output screen before
displaying the new set.
4. NOTE 1: Other than the prompt to repeat the task, there is no
input from the User in this program.
NOTE 2: This program will have 3 functions:
The function that fills the array with random numbers.
The function that generates one random number at a time (re-
use the one from Lab 10).
The function that prints out an array of integers (re-use the one
from Lab 10).
======================= Please Read
======================
Searching Through Arrays
Now that we can store large amounts of data we are ready to
learn was to process the data. One way is to search through the
data we have stored.
To search for instances of a value in an Array, you use a
looping structure - which begins with the starting position of
the Array and loops through each consecutive cell. There are
two types of searches.
If you are searching for a value where only one instance will
occur in the array (no duplicates) then you search until the
5. value is found or until you reach the end of the array. If more
than one instance can occur in the array then you must search
until you reach the end of the array. If you are not sure whether
there will be only one instance of a value or not then you
assume it could occur more than once and use the second
method.
Searching for a single instance of a value in an Array
When searching for
one instance
, you use a sentinel driven While or Do Loop. When setting up
the condition for the looping structure, you must stop when one
of two things occur:
You must stop when the value is found
OR
You must stop when you reach the end of the Array
The pseudo-code would look like this:
initialize index to the beginning index value of your Array
initialize a flag (Boolean variable) to false to represent element
not found
WHILE the flag is equal to false AND index is less than size of
Array
IF the element at Array (index) is equal to the element you
are searching for THEN
flag is assigned true (element found)
6. ELSE
increment index
END IF
END WHILE
This will cycle through all of the elements stored in the Array
and stop when the element is found OR when you are at the end
of the Array - whichever comes first.
When the Loop ends the value of index will be one of two
values. You can determine whether or not the element was
found based upon the index value.
The Index Value will either contain the position of where the
element was found OR it will be equal to the size of the array.
Remember, the condition to end the loop must be false - so the
variable that counts will contain the size of the array if the
element was not found.
When the Loop ends the value of flag will be either True or
False.
If the value of flag is True then the element was found and
index value will indicate where.
7. If the value of the flag is False then the element was not found
and index will be equal to the size of the array.
Remember:
Value was NOT FOUND:
If the value of index is equal to the size of the array AND the
flag is still false then the element was not found.
Value was FOUND:
If the value of index is NOT equal to the size of the array AND
the Boolean flag is true then this means that the element was
found and index contains the position number of where the
element was found.
NOTE 1: This is only one way to search for a element contained
within an Array. There are many other ways.
NOTE 2: This assumes there is only one instance of an element
in the Array.
Searching for duplicate instances of a value in an Array
8. If you need to search for a value that can occur more than once
in an array then you need to cycle through the ENTIRE Array
(instead of stopping when the first instance is found) and count
(using a different counter than the Loop index) how many times
the element occurred. Within each cycle, a comparison is made
between the value you are searching for and the contents of the
cell. Each time there is a match you count it by incrementing a
counter.
Initialize the counter to 0 (to start counting)
FOR (
index
is equal to beginning index value of Array,
index
is less than size of Array, increment
index
by 1)
IF the element at Array (
index
) is equal to the element you are searching for THEN
increment the counter (element found)
END IF
END FOR
In this algorithm, when the looping structure ends the counter
will either be zero or it will contain the number of instances the
value occurred within the array. If the counter is zero then there
were no instances of the value in the array.
9. Your Responsibilities in Module 11
Module Overview:
This Module continues with the topic of arrays. The focus is on
how to process data stored within an array. Searching for and
sorting data within an array is discussed.
Module Learning Objectives:
Students will be able to search for data within an array.
Students will be able to use a simple sorting routine to sort data
within an array.
Readings:
1. Read all Mini-Lectures Module 11
2. Text:
Chapter 9
Chapter 3.7 Review (Pages 143 -150)
Chapter 6.4 (Pages 321 – 323)
I will upload for you the textbook