=========================preview======================
(COMP102)midterm96S.pdf
Back to COMP102 Login to download
======================================================
The Hong Kong University of Science & Technology
COMP 102: Computer Fundamentals & Programming
Spring Semester, 1996
MIDTERM EXAMINATION
29 March, 1996 (8:30am-10:00am)

STUDENT NAME: ___________________________ STUDENT NUMBER: ___________________________ DEPARTMENT: ___________________________ LAB. SECTION: ___________________________
Instructions to Students
.
Check that you have all 10 pages.

.
Write your name, student number, department, and lab. section on this page.

.
Write your student number on top right hand corner of each page.

.
Answer all questions in the space provided.



Question 1-5 (1 point for each correct answer) (7 points)
1. Give the long form of the following acronyms:
CPU: ______________________________________
RAM: ______________________________________
OS: ______________________________________
2.
Name the piece of software that translates a high-level language program to a machine-level program:

3.
A byte is a group of (how many) ____________________ bits.

4.
4K of memory is (how many) ______________________bytes.

5.
4M of memory is (how many) ______________________KBytes.


6.
(4 points) Which of the following variable names are valid? Check ONLY those correct answers with a Y

___ i. var ___ ii. end ___ iii. not ___ iv. keyword
___ v. for ___ vi. comp102 ___ vii. 4sale ___ viii. real


7.
(4 points) Which of the following C++ statements contain variables whose values are destroy? Circle the best of answer a to e.


i) cin >> b >> c >> d;
ii) p = i + j + k;
iii) cout << "variables whose values are destroyed";
iv) cout << "a = 5";

a.
ii) only

b.
i) and ii) only

c.
i) and ii) and iv) only

d.
i), ii), iii) and iv)

e.
none of the above


8. (4 points) Suppose Flagis an integer (int) variable. The statement Flag = 13.5 > 12;
a.
causes a syntax error (missing parentheses)

b.
causes a syntax error (type mismatch, cannot compare .oat and integer)

c.
assigns Flag the value of 13

d.
assigns Flag the value of 1

e.
none of the above


Circle the best of answer a to e.
9. (4 points) Which of the following 3 code segments are equivalent? Circle the best of answer a to e.
i)
do {
action();
} while (A && B);

ii)
action();
while (A && B) {
action();
}

iii)
while (A && B) {
action();
}

a) i) & ii)
b) ii) & iii)
c) i) & iii)
d) i) & ii) & iii)
e) None of the above

10. (6 points) Rewrite the following segment of code using a switch statement.
if (x == 1)

action1();

else if (x == 2)
action2();

else if (x == 3)
action3();

else
defaultaction();

11. (6 points) Show the output of the following program. 12. (6 points) Consider the following C++ program:
#include <iostream.h> #include <iostream.h>
#include <iomanip.h> void main() { int x,y; float z; x = 5; y = 2; z = x / y; cout << setw(10) << x << "," << setw(10) << y <<