=========================preview======================
(COMP102)[1997](f)final~2427^_10108.pdf
Back to COMP102 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY COMP 102: Computer Fundamentals and Programming
Fall Semester, 1997
FINAL EXAMINATION December 10, 19967
STUDENT NAME: __________________________________ STUDENT NUMBER: __________________________________ DEPARTMENT: __________________________________ SECTION NUMBER: __________________________________ LAB SECTION: __________________________________
Instructions to Students
1.
There are 15 problems and 17 pages. Check that you have all 17 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 180 minutes.
7.
Stop writing immediately when the time is up.
For Grading Purposes Only
Problem 1 _______________ / 8
Problem 2 _______________ / 4
Problem 3 _______________ / 4
Problem 4 _______________ / 8
Problem 5 _______________ / 8
Problem 6 _______________ /15
Problem 7 _______________ / 6
Problem 8 _______________ / 6
Problem 9 _______________ / 5
Problem 10 _______________ / 8
Problem 11 _______________ / 6
Problem 12 _______________ / 6
Problem 13 _______________ / 6
Problem 14 _______________ / 4
Problem 15 _______________ / 6
TOTAL: _______________ / 100
1. (8 points) Write an int function that takes two integer arrays of the same size and returns their dot product. To compute the dot product, multiply the arrays position by position and sum the products. For example, with a[3] = {2,3,4} and b[3]={1,2,3}, the dot product is 2*1 + 3*2 + 4*3 =
20.
The function prototype is:
int dot_product(const int a[], const int b[], int size);
2. (4 points) What is the exact output of the following program?
#include <iostream.h>
int main()
{
int i=3, j=5, k=7;
for(int n=1; n<(i*j)%10; n++)
{
k = (n*k)%10;
cout << k;
}
cout << endl;
return 0;
}
3. (4 points) What is the content of the array A[] upon completion of the for loop in the following code segment?
int A[10] = {7, 2, 10, 5, 3, 6, 4, 8, 9, 1};
for (int count = 0; count < 9; count++)
if (A[count] > A[count+1])
{
int temp = A[count];
A[count] = A[count+1];
A[count+1] = temp;
}
01 4
23 56789
A
4. (8 points) Given a 3x3 array A declared as
int A[3][3];
write a bool function that tests whether, for all i, the sum of the ith row equals the sum of the ith column. For example, the array b[3][3] = {{2, 4, 5}, {4, 3, 9}, {5, 9, 7}} has this property, but the array c[3][3] = {{2, 4, 6}, {4, 3, 9}, {5, 9, 7}} does not.
The function prototype is:
bool is_equal_sums(const int A[3][3]);
5. (8 points) Write a function that is given an integer array and its size,