Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the error in the following pseudocode? The searchName function accepts a

ID: 3559167 • Letter: W

Question

What is the error in the following pseudocode? The searchName function accepts a string containing the name to search for, an array of strings containing the names, and an integer specifying the size of the array. The function searches for the name in the array. If the name is found, the string containing the name is returned; otherwise a message indicating that the name was not found in the array is returned.

Function String searchName(String name, String names[], Integer size)

Declare Boolean found Declare Integer index Declare String result

//Step through the array searching for the specified name.

While found== False AND index <=size - 1

If contains(names[index], name) Then Set found = True

Else

Set index = index +1

End if

End While

Explanation / Answer

there are three errors in above pseudo code.

First, it does not initialize the variable found with value equal to "false"

Second, it does not return the string containing the name,

Third, and if name is not found then it does not print the error message.

So the correct modified pseudo code would be,

Function String searchName(String name, String names[], Integer size)

Declare Boolean found Declare Integer index Declare String result

// intialize found

found=False

//Step through the array searching for the specified name.

While found== False AND index <=size - 1

If contains(names[index], name) Then Set found = True return names[index]

Else

Set index = index +1

End if

End While

PRINT Name not found

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote