=========================preview======================
(COMP102)Final_00.pdf
Back to COMP102 Login to download
======================================================
Hong Kong University of Science and Technology
COMP 102: Computer and Programming Fundamentals I
Fall 2000
Final Examination

19 December 2000, 12:30-3:30pm Sports Hall

Student Name: _________________________
Student Number: _________________________
Lecture & Lab Sections: _________________________
Instructions
1.
This is a closed-book, closed-notes examination.

2.
Check that you have all 19 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.

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 4 7 6
2 4 8 7
3 5 9 7
4 6 10 14
5 15 11 10
6 4 12 18
YOUR TOTAL POINTS

1. (4 points total) Assume that the following declarations have been given:
const int SIZE = 25;
double A[SIZE];

a) What is the total number of elements in array A? Answer: __________ b) What is the subscript of the first element of A? Answer: __________ c) What is the subscript of the last element of A? Answer: __________ d) Write a C++ statement that assigns the value 3 to the third element of A. Answer: ________________________________________
2. (4 points total) Consider the following array and function definitions: int array1[4] = {1, 2, 3, 4}; int array2[10];
void set4(int a[], int num) {
for (int index = 0; index <= num; index++)
a[index] = 4;
}

For each of the following function calls, mark it with True if it is correct and False if it is incorrect. You should consider both syntax and logical correctness.
a) set4(array1, array1[2]);

Answer: __________
b) set4(array1, 4);

Answer: __________
c) set4(array2, 8);

Answer: __________
d) set4(array2[4], 9);

Answer: __________
3. (5 points) What is the output of the following program?
#include <iostream.h>

int code;

void update_1(int& course_num) {
course_num = course_num + 1;
cout << course_num << endl;

code = code + 1;
cout << code << endl;
}

void update_2(int code) {
code = code + 1;
cout << code << endl;

}

int main() {
code = 102;

update_1(code);
cout << code << endl;

update_2(code);
cout << code << endl;

return 0;
}

Answer (just use as many lines as needed): 4. (6 points total)
Consider the following C++ program:
#include <iostream.h>

int main() {
char next;
int count = 0;

cin.get(next);
while (next != '\n') {
if ((count % 2) == 0)

cout << next;
count++;
cin.get(next);

}

return 0;
}

In the following, an empty space character is denoted as . and the newlinecharacter is denoted as
.. Use the same convention when you write the program output.
a) Given the following input:
a b . c d . e f . g h .

What would be the output of the program?