Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] Assume the following delcarations and fill in the table with either the type of the given expression, or "error" if appropriate.
    struct GameRec
    {
      string first, last;
      int score;
    };
    
    struct Point
    {
      double x, y;
    };
    
    int i,j;
    double w;
    Point P;
    GameRec G;
    GameRec *A;
    Point* B;
    
    expressiontype
    G
    B
    A.first
    A[i]
    A.first[i]
    A[i].first
    w + A[j].score
    B[i]
    P.x++
    G.score = w
  2. [10pts] Given the two definitions below, here are two possible function calls. For each, write the prototype that would match that function best:
    declarationsfunction calls
    struct Grades
    {
      double* A;
      int N;
      string name;
    };
    
    Grades* A;
    sort(A,10);
    
    
    
    int k = search(A[0].A,20,75.5);
  3. [80pts] Write a program that reads in a file like scoredata.txt (here's a small version to play with: smallscoredata.txt), which contains player names and game-scores for players playing an online game, and prints out the names in the usual alphabetical order, followed by the highest score acheived by that person. A run of on the small file would look like this:
    ~/$ ./prog
    smallscoredata.txt
    Betty Johnson 2400
    Andy Smith 800
    Betty Smith 2300
    I have two pieces of advice. First, look at the "Heterogeneous Data" section of the lecture notes! Second, I would sort the data first as shown below, and then run through the sorted data in order to pull out each individual's highest score. In fact, if you just get the sorting done right, you'll get most of the credit.
    smallscoredata.txtsorted the "right way"
    10
    Betty Smith 900
    Betty Johnson 1600
    Betty Johnson 2400
    Andy Smith 800
    Betty Smith 1200
    Betty Smith 2200
    Betty Johnson 1600
    Andy Smith 200
    Betty Smith 2300
    Betty Johnson 1900
    
    
    
    Betty Johnson 2400
    Betty Johnson 1900
    Betty Johnson 1600
    Betty Johnson 1600
    Andy Smith 800
    Andy Smith 200
    Betty Smith 2300
    Betty Smith 2200
    Betty Smith 1200
    Betty Smith 900