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.
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:
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.