Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112
Question 6

Sarah is developing a program to search and analyze an existing list of city names.

Open Q05 in the code editor.

It contains an array/list of city names named cities.

Sarah wants the program to:

  • accept the input of a search term (a string), or the string 99 to exit. No validation of this input is required.
  • display all the cities in the array that have the same first letter as the search term that has been input.
  • calculate and display the total number of cities in the array that begin with that same first letter.
  • display all the cities in the array that contain the search term as a substring (case-sensitive).
  • calculate and display:
    • the total number of cities in the array that contain the search term.
    • the number of characters in the longest city name that contains the search term.
    • the number of characters in the shortest city name that contains the search term.
  • display:
    • the longest city name that contains the search term.
    • the shortest city name that contains the search term.
  • repeat this entire process until the user inputs 99 to exit the program.

Write the code for the program.

Your program must function correctly even if the size or contents of the cities array is changed.

Save your code as Q05FINISHED with the correct file extension for your programming language.

An example of the expected program output is shown below:

Enter a search term or 99 to exit: Bos

Bristol
Boston
Belfast
Bostonia

4 city/cities begin with B

Boston
Bostonia

2 city/cities contain Bos
The longest city name has 8 characters
The shortest city name has 6 characters
The longest city name is Bostonia
The shortest city name is Boston

Enter a search term or 99 to exit:
[20]

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code