COM 1100 Foundations of Computer Science

Midterm Exam -- Thursday, November 2nd

Fall 2000 -- Professor Futrelle
College of Computer Science, Northeastern U., Boston, MA
This is a blue exam. The people to your left and right should have a red exam.

 

Read and follow the directions below carefully. Pay attention to any clarifications I announce or put on the board during the exam.

    Use the blue exam booklet. Do not tear out any pages from it -- cross them out if you must (don't waste time erasing). Please do all your scratch work in the blue book also. Do not do any work on this sheet and do not hand in this sheet. In answering the questions, be sure to include an explanation of how you arrived at your answer -- that's the only way I'll be able to give you any partial credit if the answer is wrong. But don't burn up a lot of your precious time writing long explanations either.
    You will have a blue or red exam. The people on each side of you must have the opposite color from you. This is a closed-book, no calculators exam lasting 65 minutes.

Question 1.
    What does the following bit of code produce? Carefully show all blank spaces where they occur using the  symbol. ( This question is not hard, but it is tricky. )

       int i = 37;
       cout << "<< i is:" << i << endl << "That's all << endl;" << "all done";
    

Question 2.
    Describe what each of the following four input statements do, or if any of them do not work, what's wrong with them. Assume m and n are integer variables with initial values 3 and 4, respectively. Assume that the user types in a sequence of one or more pairs of characters, a 6 followed by a blank, as needed, when the cin's require input.

       A: cin >> n;
       B: cin >> 5;
       C: cin >> m >> n;
       D: cin >> n >> n;

Question 3.
    Write a while statement that involves the following:

Question 4.
    What is the value of the following logical expression?

   (('a' > 'm') || ("dog" < "mouse")) && (false != true)
Explain, step-by-step, how you arrived at your answer.

Question 5.
    Write three versions of a function fun1.

  1. The function prototype.
  2. The function definition.
  3. A call to the function using the integer variable n and the number 37.34. The real variable rr should be defined and used to receive the returned value.
Description of the function:




Question 6.
    Just what is the problem with the following while loop? (Hint: I gave this example in lecture on Monday, Oct. 30th)

       int i = 0;
       while ( i < 7);
          {
           cout << i << endl;
           i = i + 1;
          }




Question 7.
    Create a for loop that does the following:

Question 8.
    This is a problem about the scope of identifiers. List what the values are at the points in the code marked below as "A" and "B" and explain your reasoning. Note that there may be more than one scope for a single identifier, so more than one value may be involved. If you analyze this problem carefully and methodically, you should not have any problems with this question.
       int g = 7;
       void fn(int arg)
          {g = arg + g; 
          }
       void main ()
          {int g = 10; // point A, what are the values of g?
           fn(g); // point B, what are the values of g inside the function fn
           		  // and what is the value of arg during this call to fn?
          }

EXTRA CREDIT -- Question 9.
    Explain the purpose of the break statement in the switch statement and give a small example of its use.