COM 1100 Foundations of Computer Science

QUIZ #2 -- Tuesday, October 3rd

Fall 2000 -- Professor Futrelle
College of Computer Science, Northeastern U., Boston, MA

 

Print your name here: ______________________________________________________________

Your ID number                    
 digits    1  2  3  4  5  6 your digit  7  9

If your digit is:

    0 or 2 answer question 3
    1 or 4 answer question 1
    3 or 5 answer question 4
    6 or 8 answer question 5
    7 or 9 answer question 2

If you feel that you cannot answer the question that you're supposed to, you may choose to answer one of the other four questions. Your maximum possible score on the quiz would then be 75 points instead of 100.

Question 1 --

1a. Give an example of a two-line comment that does not use the "//" comment delimiter.

1b. Given the variables and initial values:

     int k;
     int m = 9;
     int n = 2;
     float x = 3.8;

Show the evaluation tree for the statement:

    k = x + sqrt(m/n);

Question 2 --

2a. One or more errors in the following program can be corrected by moving one character. Show your correction.

  int main ()
     {cout << "Well, howdy!";
      return 0 };

2b. You are given the variables and initial values:

     int j = 3;
     int k = 5;
     int m = 7;

In normal algebra, the two expressions below would give the same value. But they don't necessarily do so in C++. Evaluate both statements and show the evaluation tree for the first one.

   first expression:  j/k + m/k

   second expression: (j + m)/k

Question 3 --

3a. Write out the C++ statement corresponding to this English-language description: "The parameter f is set equal to the constant GORF plus the square root of the expression: x2 plus the sine of y."

3b. Given the variables and initial values:

     int k;
     int x = 3;
     int z = 5;
show the evaluation tree for the statement:

    k = sqrt(abs(x*x - z*z));

Question 4 --

4a. Given the variables and initial values:

     int m = 5;
     int n = 2;
     float x = 5.0;

evaluate and compare the following two expressions and draw the evaluation tree for the first one:

   first expression:  m + x/n

   second expression: m + m/n

4b. Which of the following statements, A through D, are legal C++ statements?

     A: int x,
             y = 3;
         
     B: real aB;
     
     C: string "Fred";
     
     C: string boo = "Jane;"

Question 5 --

5a. Which of the following are legal identifiers for variables or function names in C++? For each illegal one state why it is illegal.

   Hi_there

   Oct2000
   
   theCompleteAnswer
   
   sink
   
   approximate-amount
   
   float
   
   AreaEqualsLength*Width
   
   3rdRockFromTheSun

5b. Given the variables and initial values:

     int m;
     float x = 1.0, y = 2.0, z = 3.0;

show the evaluation tree for the following statement:

    m = x * y + z / y;