Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
|
|
|
Suppose the program output was as follows:
&a=0x7ffff83497e0, &b=0x7ffff83497e4 a=10, b=20
|
| Give the output: |
main which
reads in two candidate names, then reads in a bunch of votes, and finally says
who won or if there was a tie.
You must not change main(), but should complete the
prototypes and definitions of the functions needed for the program to work. In
particular, you will need to define (at least) the three functions
get_names, update_counts, and
display_results.
Here is a brief description of each function. Of course, the best way to understand
how each function needs to work is by looking at the code in hw.cpp that uses
these functions, and the sample runs below.
get_names displays a prompt and then reads in two strings from the
terminal for the two candidate names. These are copied into the two strings which
are passed to the function as arguments.
update_counts takes a single name that was entered, the two candidate names,
and pointers to the two current counts.
If the given name is "END", update_counts should return false.
Otherwise rhe function compares the first name against each candidate
name, and if it matches, it updates the corresponding count and returns true.
If the provided name doesn't match either candidate's name, update_counts
should print an error message to the terminal and return true.
display_results takes in both candidate names and counts, and displays which
candidate won as well as the vote total. If both counts are the same it just prints "Tie!".
~$ |
~$ |
~$ |
~/bin/submit -c=IC210 -p=hw20 hw.cpp