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 red exam. The people to your left and right should have a blue 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.
    Write a while statement that involves the following:

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

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

   ((true == false) && ("mouse" >= "cat")) || (7 < 40)
Explain, step-by-step, how you arrived at your answer.

Question 4.
    Write three versions of a function demo.

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

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

       A: cin >> k;
       B: cin >> 19;
       C: cin >> k >> s;
       D: cin >> k >> k;












Question 6.
    This is a problem about the scope of identifiers. List what the values are at the points in the code marked below as "I" and "II" 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 m = 7;
       void voidFun(int r)
          {m = r + m; 
          }
       void main ()
          {int m = 10; // point I, what are the values of m?
           voidFun(m); // point II, what are the values of m inside the function voidFun
           		       // and what is the value of r during this call to voidFun?
          }

Question 7.
    Just what is the problem with the following if statement? (Hint: I gave examples like this in the lectures on Monday and Tuesday.)

       int mm = 10;
       if ( mm > 7);
          {
           cout << mm << endl;
          }

Question 8.
    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 kk = 683;
       cout << " kk is: << kk" << endl << kk << "That's all >> kk" << "all done";
    

EXTRA CREDIT -- Question 9.
    Give a simple example of a multiple-alternative decision structure as a way to deal with nested if statements. (Hint: This form doesn't have to use more and more indententation at each step.)