ArraysExtendedAS & A Level 9618
Search an array for a name
Linear search practice with a Boolean flag: find whether a target name exists in an array.
An array Names stores 5 student names in positions 1 to 5.
Write pseudocode that reads a target name, searches the array, and outputs Found or Not found.
Your program should
- Declare Names as ARRAY[1:5] OF STRING.
- You may assume the five names have already been stored.
- Use a Boolean flag during the search.
- Output Found or Not found.
Sample input
Sam
Sample output
Found
Starter
Pseudocode
// Names already holds five student names. Search for Target and output Found or Not found.
DECLARE Names : ARRAY[1:5] OF STRING
DECLARE Index : INTEGER
DECLARE Target : STRING
DECLARE Found : BOOLEAN
Names[1] <- "Alex"
Names[2] <- "Sam"
Names[3] <- "Riley"
Names[4] <- "Jordan"
Names[5] <- "Chris"