Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

See the bottom for how to submit your work.

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Practice Problem of
     Simple data bucketing
    Debug your code until it runs correctly. Circle below how you wrote your code.
    1. (10 pts) I was able to write the code without referring to anything.
    2. (10 pts) I had to look at the notes, but still I was able to write the code without looking at the solution.
    3. (10 pts) I had to look at solutions to finish to code.
    4. (0 pts) I didn't do this.
    If you had to look at the solution, briefly describe what you missed but understand now.
    
    
    
    
  2. [10pts] See the code below.

    ifstream fin("foo.txt");
    int count = 0;
    char c = 'x';
    while(fin)
    {
      if (c == '?')
        count = count + 1;
      fin >> c;
    }
    cout << count << endl;
    What exceptional condition would cause the program to never enter the while loop?
    
    
    
    Suppose the program entered the while loop. What would cause the program to exit the loop?
    
    
    
  3. [10Pts] Assume the following declarations, and fill in the table.
    
    ifstream fin("data.txt");
    int n = 5;
    double x = 1.5;
    char c = 'R';
    
    expressiontype
    cin
    fin
    cin >> x
    cin >> c && c != '.'
    !(fin >> n)
  4. [70pts] Write a program hw.cpp that works as follows:
    1. It reads in a file that contains the names of several students along with their hw, quiz and exam averages, e.g., input.txt.
    2. For each student, it prints out the student's name and the overall average score.
    3. When computing the average, use the following weights:
      hw: 20%, quiz: 20%, exam: 60%.
    4. In the end, the program shows the best student.
    With input.txt (download it into a VM before running your program), an example run is given below (with user input colored red):
    ~$ ./hw
    Filename: input.txt
    Brown   71.8
    Green   93.8
    Jones   82.4
    Smith   86.2
    Worth   91.2
    The best student is Green. 
    

    Your program should work for any file in the same format. Another example run with test.txt (download it into a VM before running your program):

    ~$ ./hw
    Filename: test.txt
    Abel	85.4
    Dean	88.8
    Jade	84
    Mood	78.2
    Noon	83.8
    Wren	62
    Zoom	85.2
    The best student is Dean. 
    

Turn in