=========================preview======================
(COMP102)[1997](f)midterm~2427^_10109.pdf
Back to COMP102 Login to download
======================================================
STUDENT NUMBER:______________________
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY COMP 102: Computer Fundamentals and Programming
Fall Semester, 1997
MIDTERM EXAMINATION October 23, 1997
STUDENT NAME: __________________________________ STUDENT NUMBER: __________________________________ DEPARTMENT: __________________________________ SECTION NUMBER: __________________________________ LAB. SECTION: __________________________________
Instructions to Students
1.
There are 12 problems and 10 pages. Check that you have all 10 pages.

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

3.
Write your student number on each of the following pages.

4.
Answer all questions in the space provided. Rough work should be done only on the back pages and afterwards drawn a diagonal line through it to show that it is not part of your answer.

5.
Leave all pages stapled together.

6.
The examination period will last for 120 minutes.

7.
Stop writing immediately when the time is up.


For Grading Purpose Only
Problem 1 _______________ / 10
Problem 2 _______________ / 3
Problem 3 _______________ / 3
Problem 4 _______________ / 6
Problem 5 _______________ / 8
Problem 6 _______________ / 15
Problem 7 _______________ / 10
Problem 8 _______________ / 8
Problem 9 _______________ / 10
Problem 10 _______________ / 6
Problem 11 _______________ / 6
Problem 12 _______________ / 15
TOTAL: _______________ / 100

1. (10 points) Given int a, b, c; write a logical expression, for each of the following statements, that are true when
i. b is greater than both a and c.

ii. a and b are both greater than c.

iii. b is not less than both a and c.

iv.
a, b, and b are in non-decreasing sorted order.


v.
a is even or b is odd



vi. b is not negative and a is at least twice as large as b and a
is strictly smaller than 99

vii. a is 7 or b is not 13

2. (3 points) Which of the following are valid C++ identi.ers?
i. MAX

ii. Max

iii. Ma x

iv.
max_


v.
4_u



vi. ivu

3.
(3 points) Imagine you had a computer with several gigabytes of main memory. Would you still need to have secondary memory on this computer? If so, why?

4.
(6 points) What is the value of n after the following code is executed?


int n = 0;
int x = 1;
int y = 0;
int z = -1;
if(x > 0 && y+z > 0)

n = 1;
else if(x==1 || (y <0 && z<0))
n = 2;
else
n = 3;

a) 0
b) 1
c) 2
d) 3
e) none of the above

5. (8 points) How many times is the function action() called?
int i, n;
n = 5;
action();
while(n > 0){

i = 1;

while(i <= 10){
action();
i++;

}
n--;
}

a) 1
b) 39
c) 41
d) 50
e) none of the above

6. (15 points) We want to write a function "print_triangle(int len)" that prints a triangle as follows:
print_triangle(3) ==>
/|
/.|
/--|

print_triangle(5) ==>
/|
/.|
/..|