=========================preview======================
(comp102)[2005](f)midterm~plliu^_10115.pdf
Back to COMP102 Login to download
======================================================

Hong Kong University of Science and Technology
COMP 102: Computer and Programming Fundamentals I
Fall 2005
Midterm Examination

28 October 2005
Answer



Student Name: _________________________

Student Number: _________________________

Lecture & Lab Sections: _________________________


Instructions

1.
This is a closed-book, closed-notes examination.


2.
Check that you have all 12 pages (including this cover page).


3.
Write your name, student number, lecture and lab sections on this page.


4.
Answer all questions in the space provided using a ball pen.


5.
Rough work should be done only on the back pages.


6.
Please turn off your mobile phone/pager or else you will be disqualified.





Question
Maximum Points
Your Points
Question
Maximum Points
Your Points

1
10

7
8


2
15

8
8


3
10

9
9


4
6

10
8


5
6

11
10


6
10





sub total
57

sub total
43


YOUR TOTAL POINTS






1.
(10 points)


int a = 3, b = 4, c = 5, d = 2945;
int x = 2, y = 3, z = 1;



What is the value of each of the following expressions? (Each expression should be evaluated with the same set of initial values as given above.) Mark the Boolean answers true with TRUE and false with FALSE in the space provided.



a)
8 + 3.5 * (int)6.5/2.5 ______16.4__________________




b)
5 * 2 / 6 + 15 % 4 ________4____________________




c)
-Ca * (3 + b)/2 C c++ * b _________-13________________




d)
!(b - 4)&&(-2) __________true__________________




e)
y C 3 * z + 2 ____________2________________




f)
z C (x+z)%2 + 4 ________4____________________




g)
x C 2*(3 + z) + y _________-3___________________




h)
x + 2/6 + y ____________5___________________




i)
x/z || z-1 && y _____________true__________________




j)
++x - -y-- _____________6__________________





2.
(15 points total)


a)
(3 points) What is the output on the screen after the following code is executed?




int n = -1, m = 1, result = 0;
if (m > 1) if (n > 0)
result = 1;
else
result = 2;
cout << result << endl;


Answer: _______0

b)
(3 points) What is the output on the screen after the following code is executed?



int n = 6, a = -1, b = 2;

switch((--n)%4){
case 0: n++;
break;
case 1: n *= ++a;
case 2: n +=--b;
default:n++;
}
cout << n;

Answer: ____________2________________________________________________


c)
(2 points) What is the output on the screen after the following code is executed?




int x = 0, y = 0, z = 1, n = 0;
if (z < x || y >=z &