9ArraysHard15 marks
A program is required to enable voting in class surveys, for example to find the most popular smartphone.
The one‑dimensional (1D) array Options[] is used to store between 2 and 12 options on which users can vote.
The one‑dimensional (1D) array Votes[] is used to store the votes of between 2 and 1000 users.
The one‑dimensional (1D) array VoteCount[] is used to store the number of votes for each of the options. The array index represents the option number.
Write a program for the following requirements:
• Initialise all the arrays before they are used.
• Input and validate the number of options and the number of voters.
• Input each of the required options and store them in the array Options[]
• Display the list of options for each voter and allow each voter to input their preferred option.
Validate this input and store it in the array Votes[]
• Once all the votes have been input, count the number of voters who chose each option and find the most and least popular options.
• Output the most and least popular options as well as the number of voters who selected each of these options.
The program does not need to identify if two or more options are the equal most or least popular.
You must use pseudocode or program code, and add comments to explain how your code works.
Do not declare arrays, variables or constants for this algorithm; assume this has been done.
Initialisation must be carried out as appropriate.
All inputs and outputs must contain suitable messages.
Answer
0 words