54.1k views
0 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?
Option 1: The procedure returns true if the city appears only once in the list.
Option 2: The procedure returns false if the city appears more than once in the list.
Option 3: The procedure counts the total number of cities in the list.
Option 4: The procedure doesn't check for the presence of the city.

User Nolo
by
7.9k points

1 Answer

5 votes

Final answer:

The procedure returns false if the city appears more than once in the list.

Step-by-step explanation:

The procedure described counts the occurrences of a specific city name in a given list of cities. If the city appears more than once, the procedure returns true; otherwise, it returns false. It does not count the total number of cities in the list, nor does it check for the presence of the city name without counting. Therefore, option 2: The procedure returns false if the city appears more than once in the list is the correct statement regarding the procedure's testing.

User Urmil Jindal
by
8.8k points