Topical Information

Here are a few questions to help you clarify your understanding of input.

Directions

For each of the code fragments below, show what happens when the user types this sequence of characters:

   9+4uaq^-5*-7

That is, for each code fragment:

  1. show the values of all involved variables
  2. tell the position in the input stream where processing stops
  3. explain any errors that arise during processing ...or state that no errors occurred

You should assume that each fragment is independent of the others (i.e. so each input begins at the '9' in the stream of input).

The type of the variables used is indicated by their first letter (c is char, s is short, etc.).

Questions

  1.     cin >> c1 >> c2 >> c3;
    
       c1:  '9'
       c2:  '+'
       c3:  '4'
    
       left:  uaq^-5*-7
    
       errors:  none
    
    

  2.     cin >> s1 >> c1 >> s2;
    
       s1:  9
       c1:  '+'
       s2:  4
       
       left:  uaq^-5*-7
    
       errors:  none
    
    

  3.     cin >> s1 >> s2 >> s3;
    
       s1:  9
       s2:  4
       s3:  n/a
    
       left:  uaq^-5*-7
    
       error:  fail
    
    

  4.     cin >> s1 >> s2 >> c1;
    
       s1:  9
       s2:  4
       c1:  'u'
    
       left:  aq^-5*-7
    
       errors:  none
    
    

  5.     cin >> d1 >> d2 >> c1;
    
       d1:  9.0
       d2:  4.0
       c1:  'u'
    
       left:  aq^-5*-7
    
       errors:  none
    
    

  6.     cin >> s1 >> c1 >> s2
            >> c2 >> c2 >> c2
            >> c3 >> d3 >> c4
            >> d4;
    
    
       s1:  9
       c1:  '+'
       s2:  4
       c2:  'u'
       c2:  'a'
       c2:  'q'
       c3:  '^'
       d3:  -5.0
       c4:  '*'
       d4:  -7.0
    
       left:  nothing
    
       errors:  none