74.0k views
3 votes
The procedure below is intended to return true if a particular city name (cityName) appears more than once in a list of cities (cityList), and false if it does not appear, or only appears once in the list.

PROCEDURE CityRepeat (cityList, cityName) counter ← 0 FOR EACH city IN cityList IF (city = cityName) counter ← counter + 1 IF (counter = 1) RETURN false ELSE RETURN true

Which of the following statements about the testing of this procedure is true?
1) The procedure will return true if the city name appears more than once in the cityList
2) The procedure will return false if the city name does not appear in the cityList
3) The procedure will return false if the city name appears only once in the cityList
4) The procedure will return true if the city name does not appear in the cityList

1 Answer

2 votes

Final answer:

The provided procedure checks if a city name appears more than once in a list of cities and returns true or false accordingly.

Step-by-step explanation:

The procedure provided is intended to determine whether a particular city name appears more than once in a given list of cities. It starts with a counter set to 0. Then, for each city in the cityList, it checks if the city matches the cityName. If it does, the counter is incremented. If the counter is equal to 1 at the end, it means the cityName appears only once and the procedure returns false. Otherwise, if the counter is greater than 1, it means the cityName appears more than once and the procedure returns true.

Therefore, statement 1) is true because the procedure will return true if the cityName appears more than once in the cityList. Statement 2) is false because the procedure does not consider the case when the city name does not appear at all. Statement 3) is true because the procedure will return false if the cityName appears only once in the cityList. Statement 4) is false because the procedure does not handle the case when the city name does not appear in the cityList.

User Drmarvelous
by
8.0k points