=========================preview======================
(COMP102)final_2000fall_sol.pdf
Back to COMP102 Login to download
======================================================
Solution and Marking Scheme for Final Exam (Fall 2000)
1.
(4 pts total)

a) 25 (1 pt) b) 0 (1 pt) c) 24 (1 pt) d) A[2] = 3; (1 pt)

2.
(4 pts total)

a) True (1 pt) b) False (1 pt) c) True (1 pt) d) False (1 pt)

3.
(5 pts total)

103 (1 pt) 104 (1 pt) 104 (1 pt) 105 (1 pt) 104 (1 pt)

4.
(6 pts total)


a) a.de.h (1 pt) b) 1234567891.1 (1 pt)
5. (15 pts total)
a) int table[3][5] (1 pt) row < 3; row++ (2 pts) col < 5; col++ (2 pts) row * 10 + col (3 pts)
b) const int data[][5], int row, int size (2 pts; ok to have no const)
double sum = 0.0; (1 pt) for (int col = 0; col < size; col++) (3 pts) sum += data[row][col]; return (sum / size); (1 pt)
6. (4 pts total)
#include <iostream.h> #include <fstream.h>
int main() { ifstream ins; ofstream outs; int number; // new (1 pt)
ins.open("input.dat"); outs.open("output.dat"); // new for (int i = 0; i < 10; i++) { ins >> number; cout << number << " "; outs << number << " "; } ins.close(); outs.close(); // new // new (1 pt) (1 pt) (1 pt)
} return 0;
7. (6 pts total)

// void selectsort(int data[], int size) {
void selectsort(char data[], int size) { // new (1.5 pt)

for (int rightmost = size -1; rightmost > 0; rightmost--) {
int max_index = 0;
for (int current = 1; current <= rightmost; current++)

// if (data[current] > data[max_index]) if (data[current] < data[max_index]) // new (1.5 pt) max_index = current; // if (data[max_index] > data[rightmost]) { if (data[max_index] < data[rightmost]) { // new (1.5 pt)
// int temp = data[max_index]; char temp = data[max_index]; // new (1.5 pt) data[max_index] = data[rightmost]; data[rightmost] = temp;
}
}
}

8. (7 pts total)
a) bsearch(list, 0, 11, 19) (1 pt)
b) bsearch(list, 0, 4, 19) (1 pt)
bsearch(list, 3, 4, 19) (1 pt)
c) bsearch(list, 0, 11, 72) (1 pt)
bsearch(list, 6, 11, 72) (1 pt)
bsearch(list, 9, 11, 72) (1 pt)
bsearch(list, 9, 9, 72) (1 pt)
9. (7 pts total)
7 November: Gore = 350 (1 pt)
7 November: Bush = 400 (1 pt)
10 November: Gore = 500 (1 pt)
10 November: Bush = 450 (1 pt)
13 November: Gore = 50 (1 pt)
13 November: Bush = 250 (1 pt)
The winner is: Bush (1 pt)
10. (14 pts total)
a) trig.vertex[0].x = 2; (0.5 pt)
trig.vertex[0].y = 1; (0.5 pt)
trig.vertex[1].x = 2; (0.5 pt)
trig.vertex[1].y = 5; (0.5 pt)
trig.vertex[2].x = 6; (0.5 pt)
trig.vertex[2].y = 3; (0.5 pt)
b) TriKind determine_tri_kind(Triangle tri); (3 pts)
c) trig.kind = determine_tri_kind(trig); (3 pts)
d) switch (trig.kind) { (1 pt)
case equilateral: cout << "equilateral\n"; break; (1 pt)
case isosceles: cout << "isosceles\n"; break; (1 pt)
case rightangled: cout << "rightangled\n"; break; (1 pt)
case other: cout << "other\n"; break; (1 pt)
}

11. (10 pts total)
a) count <= number (1 pt) previous + pre_previous + pre_pre_previous (1 pt) previous = current (1 pt) current