Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10Pts] Assume the following declarations, and fill in the table.
    
    ifstream fin("data.text");
    int n = 5;
    double x = 1.5;
    char c = 'R';
    
    expressiontype
    cin
    fin
    cin >> x
    cin >> c && c != '.'
    fin >> n ? n*0.5 : n*0.75oops -- ignore this part!

  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. [10pts] Consider the following source code:
    
      int a, b;
      cin >> a >> b;
      int i=1;
      while( i < a )
      {
        int j = b;
        while ( j >= 0 ) 
        {
          cout << i*j << " ";
          j = j - 2; 
        }                     
        cout << endl;
        i = i + 1;
      }
    
    Suppose the user gives the following input to the program:
     3 3 
    Write below the output of the program, given the above input. Try it without compiling and running the code.
    
    
    
    
    
    
  4. [70pts] 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 1920 and 2019.

    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 ther 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
    adult
    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
    4 adults and 4 children
    
    ~/$ ./hw
    Filename: names2.txt
    10 adults and 9 children
    
    ~/$ ./hw
    Filename: badname.txt
    File not found!