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 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++
  2. [90pts] 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 functions given in the starter code. It is important to learn how to write code within the limitations.
    5. The code compiles as it is. You can complete and test each function one by one.

    Submit: ~/bin/submit -c=IC210 -p=hw31 hw.cpp

    Turn In the codeprint of your source code.

    ~/$ ./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