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 today's lecture notes carefully. 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. [4pts] Using the hexadecimal system, calculate the following (the result must be in the same base):

     0x3c + 0x94 =
  3. [8pts] Consider the following program and program output. Annotate the memory diagram on the right with the variable names and their values so that the diagram shows the state of memory just after the code has been executed.
    code output
    
    int p;
    int q;
    p = 5; 
    p = p + 7;
    q = p - 2;
    
    cout << &p << endl;
    cout << &q << endl;
    
    0x7ffff79351d0
    0x7ffff79351dc
    
      
    memory diagram
       address              value          (annotate variables p and q)
    0x000000000000
    ...
    0x7ffff79351c4
    0x7ffff79351c8
    0x7ffff79351cc
    0x7ffff79351d0
    0x7ffff79351d4    
    0x7ffff79351d8    
    0x7ffff79351dc            
    ...
    0xffffffffffff
    
  4. [10pts] Consider the following code:
    
    int p;
    p = 1;
    cout << &p << endl;
    {
      int p;
      cout << &p << endl;
    }
    cout << &p << endl;
    
  5. [10pts] Consider the following code. Fill out the table on the right.
    
    string s, t, r;
    
    cin >> s;
    if( s == "hello" )
    {
      cin >> t;
      string s;
      s = s + "." + t + ".world";
    }
    
    cin >> r;
    s = s + "." + r + ".programmers";
    cout << s << endl;
    
    Input to the programProgram output
    hello wonderful go
    computer science nice
  6. [20pts] Consider the following code below. Fill out the table.
    
    char c1, c2;
    string s1, s2;
    
    cin >> c1;
    if( c1 == 'I' )
    {
      cin >> c2; 
      if( c2 == 'C' )
      {
        cin >> s1;
        cout << c1 << c2 << s1 << endl;
      }
    }
    else
    {
      if( c1 == 'i' )
      {
        cin >> s1 >> s2;
        cout << c1 << s1 << " " << s2 << endl;
      }
      else
      {
        cout << c1 << endl;
      }
    }
    
    Input to the program Program output
    IC210 rocks
    Ic210 rocks
    ic210 rocks
    210 really rocks
    Homework Homework
  7. [18pts] Consider the declarations and initializations below. Fill in the table with the type and values for the given expressions.

    Note: each expression should be taken as independent. I.e. if one expression modifies some variable values, those modifications do not carry over to the next expression.

    
    int n, m;
    double x = 17.8;
    char c = 'A';
    bool b = false;
    n = 5;
    m = 3;
    
    expressiontypevalue
    n + 2
    n / m
    n % n
    n * (x = 20.1)
    15 < x || x <= 5
    !x && n
    c + 3
    c == 'v'
    c + 3 == 68

Turn in (Due: 0800 on the next class day)