Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Mandatory Practice Problems. 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] Assume the following delcarations and fill in the table with either the type of the given expression, or "error" if appropriate.
    
    struct Point
    {
      double x, y;
    };
    
    struct Trial
    {
      double stime, etime;
      Point* ways;
      int numways;
    };
    
    struct Subject
    {
      string name;
      int id;
      Trial pre, post;
    };
    
    Subject S;
    Subject* A;
    int i, j;
     
    expressiontype
    S.id
    A[i]
    A.pre.ways[i][j]
    S.post = A[i].pre;
    A[i].post.ways
    S.pre.ways[i]
    A[i].id = S.ways[i].y
    A[i].pre.ways[j].x
    A[i].post.ways.x
    S.pre.numways++
  3. [20pts] Suppose we have the structs defined below, and variable V assigned and initialized as shown in the picture.
    
    struct Pos
    {
      int row, col;
    };
    struct Guy
    {
      char sym;
      Pos loc;
    };
    struct Group
    {
      Guy *peeps;
      int num;
    };
    Write a statment(s) that:
    1. changes the value 15 to 50:
    2. changes the $ to a %:
    3. swaps location 35,4 with location 21,44:
    4. Show, by annotating the above diagram, what would change if the following statement is executed:
      
      V[1].peeps = V[2].peeps;
      
  4. [60pts] Download hw.cpp.
    The program is supposed to work as follows:
    • It reads a data file containing offerred course sections like sections.txt.
    • Then, it allows the user to search for sections based on a course name, a section number, or a day in a week.
    On the right is a sample run (with user input in red).

    Your task:

    1. Read the starter code hw.cpp carefully and understand what each function does or should do. (You may want to refer to the course notes on pass-by-reference and sorting-and-search).
    2. Add code in hw.cpp so that the program works correctly.
    3. Tip: There is no space around ','. Searching based on days needs string manipulations (i.e., accessing each letter in a given string).
    4. Don't touch the main function given in the starter code.

    Turn in

    • Written portion: Turn in the hardcopy in class.
    • Programming portion: Submit your code hw.cpp to the submission server by using the command below (executed from the same directory as your hw.cpp).
      ~/bin/submit -c=IC210 -p=hw28 hw.cpp
      
    ~/$ ./hw
    Filename: sections.txt
    >  course EE301
    EE301 1111 M1,TR12
    EE301 2222 M2,WF12
    EE301 5555 M5,TR56
    
    >  section 4040
    SC112 4040 M4,WF4,T56
    
    >  day F
    HE112 1001 MWF1
    HE112 1002 MRF1
    HE112 4001 MWF4
    HE112 9001 WF9
    HE112 5001 MWF5
    EE301 2222 M2,WF12
    EE327 3333 MWF3,R34
    SC112 3000 M3,WF3,T34
    SC112 4000 TRF4,W34
    SC112 4040 M4,WF4,T56
    SC112 8012 TR8,F12
    
    >  day R
    HE112 1002 MRF1
    HE112 2001 T2,R12
    HE112 6001 MWR6
    EE301 1111 M1,TR12
    EE301 5555 M5,TR56
    EE327 3333 MWF3,R34
    SC112 4000 TRF4,W34
    SC112 5534 MTR5,W34
    SC112 8812 TR8,W12
    SC112 8012 TR8,F12
    
    >  course EE327
    EE327 3333 MWF3,R34
    
    >  section 3333
    EE327 3333 MWF3,R34
    
    >  quit
    
    sections.txt
    N = 17
    HE112 1001 MWF1
    HE112 1002 MRF1
    HE112 2001 T2,R12
    HE112 4001 MWF4
    HE112 9001 WF9
    HE112 5001 MWF5
    HE112 6001 MWR6
    EE301 1111 M1,TR12
    EE301 2222 M2,WF12
    EE301 5555 M5,TR56
    EE327 3333 MWF3,R34
    SC112 3000 M3,WF3,T34
    SC112 4000 TRF4,W34
    SC112 4040 M4,WF4,T56
    SC112 5534 MTR5,W34
    SC112 8812 TR8,W12
    SC112 8012 TR8,F12