Name: ____________________________________________________ Alpha: _____________ Section: ________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

Due: Before 0800 on next class day

  1. (10 pts) Read today's lecture notes. Honestly declare how you read the notes.
    1. (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
    2. (10 pts) I read the notes carefully, but I don't really understand the following points well:
      
      
      
    3. (0 pts) I didn't read the notes carefully.
  2. [10pts] What will be the output of the following program? A similar question will appear in the exam. See if you can do this manually.
    
    #include <iostream>
    using namespace std; 
    
    int foo(double x, double* y);
    
    int main() 
    {
      double a = 8.5;
      double b = 10.1;
      cout << "ONE " << foo(a, &b) << endl;
      cout << "TWO " << a << " " << b << endl;
      return 0;
    }
    
    int foo(double x, double* y) 
    {
      x = x + 2;
      *y = *y + 2;
      cout << "THREE " << x << " " << (*y) << endl;  
      return x;
    }
    
    Give the output:
    
    
  3. [80pts] Download hw.cpp. The program contains a 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.

    Here are some sample runs (user input in green):

    ~$ ./hw
    Candidate names: Pepsi Coke
    Enter votes, ending with "END":
    Pepsi
    Pepsi
    Coke
    Coke
    Coke
    Pepsi
    Coke
    END
    Coke wins with 4 of 7 votes
    ~$ ./hw
    Candidate names: IT CS
    Enter votes, ending with "END":
    IT
    CS
    CS
    IT
    Aero
    Invalid name
    IT
    IT
    CS
    CS
    EE
    Invalid name
    END
    Tie!
    
    ~$ ./hw
    Candidate names: Tacos Sushi
    Enter votes, ending with "END":
    Tacos
    Pizza
    Invalid name
    Sushi
    Tacos
    END
    Tacos wins with 2 of 3 votes
    

Submit to the submission server (due: 0800 on the next class day)

 ~/bin/submit -c=IC210 -p=hw18 hw.cpp 
Bring to class