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 lecture notes for today. 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] Consider the following code:
    
    char next;
    int count = 0, total = 0;
    cin >> next;
           _______________a_______________________
          /                                       \
    while ((next == '0' || next == '1') && count < 3)      
    {      \_________/
                b               c
                               / \
      total = total*2 + next - '0';
              \__________________/
                       d
    
      count = count + 1;
      cin >> next;
    
    }
    cout << total << endl;
    \___________/
          e
    
    
    For each expression denoted left, fill in the type of the expression.
    type
    a
    b
    c
    d
    e

  3. [80pts] Write a program with a source file name hw.cpp that reads in names and birthdates from a given file and reports the number of adults and children in the list.

    Your program should start by asking for a filename from the command line. If the file does not exist, print an error message and exit.

    Each line in the file will have a single name and birthday. Each name is a single string, and each birthday is formatted as MM/DD/YY, so for example the birthday 08/04/32 means August 4, 1932. You may assume that each birthday is between 1922 and 2021.

    After reading in the file, your program should report the number of adults and children in the file. For the purposes of this problem, an adult is anyone born on or before 09/27/00. Anyone born after that date is considered a child.

    On the right is a listing of names1.txt, along with an indication of who is an adult or a child:

    John 09/04/01
    Dennis 09/09/00
    Margaret 08/17/00
    Ken 12/17/20
    Barbara 11/07/00
    Linus 09/28/00
    Grace 12/09/06
    Frances 08/04/32
    
    child
    adult
    adult
    child
    child
    child
    child
    adult
    

    We provide two sample files for testing: names1.txt and names2.txt. Your program must work for any file that is correctly formatted, not just these two.

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

    ~/$ ./hw
    Filename: names1.txt
    3 adults and 5 children
    
    ~/$ ./hw
    Filename: names2.txt
    9 adults and 10 children
    
    ~/$ ./hw
    Filename: badname.txt
    File not found!
    

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

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