Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

Counting machine for ballots cast.

★☆☆

A game show allows contestants to ask the audience to help them choose a correct answer to a question from four possible answers. Audience members each have a small hand-held terminal on which they can press one of four buttons labelled A, B, C or D. As the audience vote, their selection is appended to a list. Once the time for voting has ended the results are collated and displayed to the contestant.

Voting count

Make

Write a program to output the total number of votes cast for each answer. The votes cast were: “A”, “B”, “B”, “B”, “B”, “C”, “C”, “D”, “A”, “B”, “A”, “B”, “A”, “B”, “D”, “B”, “C”, “B”, “B”, “A”.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called count_votes that:

  1. Takes a parameter called ballot that is the list of the votes cast.
  2. Counts the number of votes for A, B, C and D. Any other data in the list is ignored.
  3. Returns an array of the results. Index 0 is the count for A, index 1 is the count for B, index 2 is the count for C and index 3 is the count for D.

Complete the main program so that:

  1. The count_votes subprogram is called.
  2. The results of the vote are output.

Typical inputs and outputs from the program would be:

Answer A: 5
Answer B: 10
Answer C: 3
Answer D: 2
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// Voting count program

using System;
using System.Collections.Generic;

class Submission
{
---
    // -------------------------
    // Subprograms
    // -------------------------
    // Function to count votes A, B and return results as an array
    static int[] count_votes(List ballot)
    {
---
        int[] result = { 0, 0, 0, 0 };
---
        // Look at each vote cast
        foreach(string vote in ballot) 
        {
---
            // Count A, B, C, D
            switch (vote) 
            {
---
                case "A":
                    result[0] += 1;
                    break;
                case "B":
                    result[1] += 1;
                    break;
                case "C":
                    result[2] += 1;
                    break;
                case "D":
                    result[3] += 1;
                    break;
---
            }
---
        }
---
        return result;
---
    }


---
    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        List votes = new List {"A", "B", "B", "B", "B", "C", "C", "D", "A", "B", "A", "B", "A", "B", "D", "B", "C", "B", "B", "A"};
        int[] result = count_votes(votes);
---
        Console.WriteLine($"Answer A: {result[0]}");
        Console.WriteLine($"Answer B: {result[1]}");
        Console.WriteLine($"Answer C: {result[2]}");
        Console.WriteLine($"Answer D: {result[3]}");
---
    }
}
</pre>
</dw-parsons-puzzle>

</details>