=========================preview======================
(COMP102)final96S.pdf
Back to COMP102 Login to download
======================================================
The Hong Kong University of Science & Technology COMP 102: Computer Fundamentals & Programming
Spring Semester, 1996
FINAL EXAMINATION
29 May, 1996 (8:30am - 11:30am)

STUDENT NAME: STUDENT NUMBER: DEPARTMENT: LAB. SECTION:

Instructions to Students
.
Check that you have all 12 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.


For Use by Grader Question 1-4 __________________ / 12 Question 5 __________________ / 16 Question 6 __________________ / 5 Question 7 __________________ / 5 Question 8 __________________ / 4 Question 9 __________________ / 3 Question 10 __________________ / 10 Question 11 __________________ / 8 Question 12 __________________ / 10 Question 13 __________________ / 5 Question 14 __________________ / 22
TOTAL: __________________ / 100


STUDENT NUMBER:______________________

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

___ i. break ___ ii. end ___ iii. not ___ iv. repeat
___ v. begin ___ vi. comp102 ___ vii. 4sale ___ viii. real



2.
(3 points) Which of the following C++ statements are valid?


i) enum yesno {yes, no} yn;
ii) enum grade {A,B,C,D,F};
iii) enum num {a, b=3, c, d, e=1, f, g};
iv) enum num2 {a=1, b=1, c=1};


a.
i) and ii) only

b.
i) ii) and iii) only

c.
i) and iii) and iv) only

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

e.
none of the above


3. (3 points) Suppose i is an integer (int i) and A is an array (int A[10]). The sequence of statements i = 20; A[i] = i;
a.
causes a compile time error

b.
always causes a run time error

c.
has absolutely no effect on your program

d.
always causes some errors in your program behaviour

e.
none of the above



Circle the best of answer a to e.
4. (3 points) What is the output of the following program?
#include <iostream.h>
void main() {
for (int i=0; i<(i+5)/2; i++) {
cout << i;
}
}

a.
0123

b.
012

c.
01

d.
0

e.
none of the above



Circle the best of answer a to e.
COMP102 Spring 96 HKUST 2 of 12
5. (5 points)
a. Given the following bubble sort program
void bubble(int data[], int size, int& count)

{
int temp, rightmost, current;

count = 0;
rightmost = size - 1;
while (rightmost > 0) {

current = 0;

while ((current < rightmost)) {
count++;
if (data[current]>data[current+1]) {

temp = data[current];
data[current] = data[current+1];
data[current+1] = temp;

}

current++;
}
rightmost--;


}
}

#include <iostream.h>
#include <iomanip.h>
int main() {

int A[8] = { 10,4,6,9,25,5,18,3 };

int n;

for (int i=0; i<8; i++)
cout << setw(3) << A[i];

bubble(A, 8, n);

cout << endl;
for (int i=0; i<8; i++)
cout << setw(3) << A[i];

cout << endl <<