SlideShare a Scribd company logo
1 of 10
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 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
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)
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.
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
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.
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
Please Please Please Read the instructions and do everything li.docx

More Related Content

Similar to Please Please Please Read the instructions and do everything li.docx

Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
Aftabali702240
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
adinathassociates
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
allenbailey
 

Similar to Please Please Please Read the instructions and do everything li.docx (20)

Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
 
java I am trying to run my code but it is not letting me .pdf
java    I am trying to run my code but it is not letting me .pdfjava    I am trying to run my code but it is not letting me .pdf
java I am trying to run my code but it is not letting me .pdf
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Standard algorithms
Standard algorithmsStandard algorithms
Standard algorithms
 
Selection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptxSelection-sort-in-algorithm and complexity.pptx
Selection-sort-in-algorithm and complexity.pptx
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
unit 5 stack & queue.ppt
unit 5 stack & queue.pptunit 5 stack & queue.ppt
unit 5 stack & queue.ppt
 
Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
ppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptxppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptx
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Lecture 09.pptx
Lecture 09.pptxLecture 09.pptx
Lecture 09.pptx
 

More from tienmixon

.2002200101 to 02.$ of Sale.docx
.2002200101 to 02.$ of Sale.docx.2002200101 to 02.$ of Sale.docx
.2002200101 to 02.$ of Sale.docx
tienmixon
 
. Comet Halley has an orbital period of 75 years and when it enter.docx
. Comet Halley has an orbital period of 75 years and when it enter.docx. Comet Halley has an orbital period of 75 years and when it enter.docx
. Comet Halley has an orbital period of 75 years and when it enter.docx
tienmixon
 
. In the exposition of a short story, __________. (Points 3) .docx
. In the exposition of a short story, __________. (Points  3)   .docx. In the exposition of a short story, __________. (Points  3)   .docx
. In the exposition of a short story, __________. (Points 3) .docx
tienmixon
 
---Quantitative Project  World Income and Health Inequality.docx
---Quantitative Project  World Income and Health Inequality.docx---Quantitative Project  World Income and Health Inequality.docx
---Quantitative Project  World Income and Health Inequality.docx
tienmixon
 

More from tienmixon (20)

.  After viewing the entire video, summarize the key ideas in the le.docx
.  After viewing the entire video, summarize the key ideas in the le.docx.  After viewing the entire video, summarize the key ideas in the le.docx
.  After viewing the entire video, summarize the key ideas in the le.docx
 
.1. Do you agree or disagree with the following statement Defen.docx
.1. Do you agree or disagree with the following statement Defen.docx.1. Do you agree or disagree with the following statement Defen.docx
.1. Do you agree or disagree with the following statement Defen.docx
 
. Theorize how socialization and culture produces conformity to soci.docx
. Theorize how socialization and culture produces conformity to soci.docx. Theorize how socialization and culture produces conformity to soci.docx
. Theorize how socialization and culture produces conformity to soci.docx
 
. The information is below but I was thinking like 5 bullet points e.docx
. The information is below but I was thinking like 5 bullet points e.docx. The information is below but I was thinking like 5 bullet points e.docx
. The information is below but I was thinking like 5 bullet points e.docx
 
.2002200101 to 02.$ of Sale.docx
.2002200101 to 02.$ of Sale.docx.2002200101 to 02.$ of Sale.docx
.2002200101 to 02.$ of Sale.docx
 
.4 Verbs like gustarfascinarModelo A él le fascina viajar..docx
.4 Verbs like gustarfascinarModelo A él le fascina viajar..docx.4 Verbs like gustarfascinarModelo A él le fascina viajar..docx
.4 Verbs like gustarfascinarModelo A él le fascina viajar..docx
 
..01 to 02.docx
..01 to 02.docx..01 to 02.docx
..01 to 02.docx
 
. Alicia brought her lunch today but now a coworker has asked her .docx
. Alicia brought her lunch today but now a coworker has asked her .docx. Alicia brought her lunch today but now a coworker has asked her .docx
. Alicia brought her lunch today but now a coworker has asked her .docx
 
. Select one of the following questions and develop an essay of ap.docx
. Select one of the following questions and develop an essay of ap.docx. Select one of the following questions and develop an essay of ap.docx
. Select one of the following questions and develop an essay of ap.docx
 
. Place each adjective clause in the following sentences in italic f.docx
. Place each adjective clause in the following sentences in italic f.docx. Place each adjective clause in the following sentences in italic f.docx
. Place each adjective clause in the following sentences in italic f.docx
 
. Comet Halley has an orbital period of 75 years and when it enter.docx
. Comet Halley has an orbital period of 75 years and when it enter.docx. Comet Halley has an orbital period of 75 years and when it enter.docx
. Comet Halley has an orbital period of 75 years and when it enter.docx
 
. How does conception normally occur, and how have beliefs about it .docx
. How does conception normally occur, and how have beliefs about it .docx. How does conception normally occur, and how have beliefs about it .docx
. How does conception normally occur, and how have beliefs about it .docx
 
. (TCO 1) How does managerial and financial accounting differ in t.docx
. (TCO 1) How does managerial and financial accounting differ in t.docx. (TCO 1) How does managerial and financial accounting differ in t.docx
. (TCO 1) How does managerial and financial accounting differ in t.docx
 
. In the exposition of a short story, __________. (Points 3) .docx
. In the exposition of a short story, __________. (Points  3)   .docx. In the exposition of a short story, __________. (Points  3)   .docx
. In the exposition of a short story, __________. (Points 3) .docx
 
. Which of the following is a factor involved in communicating us.docx
.  Which of the following is a factor involved in communicating us.docx.  Which of the following is a factor involved in communicating us.docx
. Which of the following is a factor involved in communicating us.docx
 
. Consider the following variables. For each one (a) create a resea.docx
.  Consider the following variables. For each one (a) create a resea.docx.  Consider the following variables. For each one (a) create a resea.docx
. Consider the following variables. For each one (a) create a resea.docx
 
-this is a research on your own day to complete your annotated bibli.docx
-this is a research on your own day to complete your annotated bibli.docx-this is a research on your own day to complete your annotated bibli.docx
-this is a research on your own day to complete your annotated bibli.docx
 
---Quantitative Project  World Income and Health Inequality.docx
---Quantitative Project  World Income and Health Inequality.docx---Quantitative Project  World Income and Health Inequality.docx
---Quantitative Project  World Income and Health Inequality.docx
 
-I need part A and part B completed by Wednesday April 10th at 9pm..docx
-I need part A and part B completed by Wednesday April 10th at 9pm..docx-I need part A and part B completed by Wednesday April 10th at 9pm..docx
-I need part A and part B completed by Wednesday April 10th at 9pm..docx
 
-Describe and explain the function of the following structures of th.docx
-Describe and explain the function of the following structures of th.docx-Describe and explain the function of the following structures of th.docx
-Describe and explain the function of the following structures of th.docx
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

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