logo CodeStepByStep logo

ClassPresidents

Language/Type: VB file input

Write a subroutine named ClassPresidents that tallies votes for presidents of two school classes. Somehow the vote tallies for sophomore and junior class presidents got mixed up! Your subroutine should accept as its parameter a string representing a file name of vote results. It should output the next sophomore and junior class presidents. The file format looks like the following:

Jared s 25 Sophie j 12 Tom j 44 Isaac s 30 Emily s 60 Russ s 23 Madison j 20

The file repeats the pattern name year votes. The year is either "s" for sophomore or "j" for junior. Your program should output the candidate in each presidential race with the most votes, and how many votes they got. Specifically, if this file were named candidates.txt, the call of ClassPresidents("candidates.txt") should produce the following output:

Sophomore Class President: Emily (60 votes)
Junior Class President: Tom (44 votes)

You may assume that the file exists and is readable. You may also assume that there are no ties and that each class has one single person who received the most votes.

Function: Write a VB function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.