=========================preview======================
(COMP102)Midterm_Sol_2000Fall.pdf
Back to COMP102 Login to download
======================================================
Solution and Marking Scheme for Midterm Examination
(for version 1 & 3)
1.
a) N (1 point) b) N (1 point) c) Y (1 point) d) N (1 point) e) Y (1 point)
2.
a) 0.5 (1 point) b) 6.1 (1 point) c) 9.1 (1 point) d) 18 (1 point) e) 0 (1 point) f) 3 (1 point) g) 3.33333 (ok to have 1 or more decimal places) (1 point) h) 0 (1 point) i) 26 (1 point) j) 18 (1 point)
3.
#include <iostream.h> (1 point) int main() (2 points)
int a; (1 point) cout << "a = " << a; (1 point) cout << endl; (1 point) return 0; (1 point) } // end of program or } /* end of program */ (1 point)
4.
7 (4 points)
5.
a) 2 (2 points) b) 14 (2 points) c) 9 (2 points)
6.
c (8 points)
7.
a) 1.3.5.7.9. (2 points) b) 1.2.3.4.6.7.8.9. (2 points) c) 1.2.4.5.7.8. (2 points)
8.
(ok to write multiple digits in each box) a) 15.14.13.12 (3 points) b) 10.14.30.40 (3 points) c) 7.99.0.140 (3 points) d) 7.14.30.140 (3 points)
9. a) col_count = 1 (2 points) b) "*" (2 points) c) " " (2 points) d) begin_pos <= end_pos or begin_pos <= EDGE_LEN or
EDGE_LEN <= end_pos (2 points) e) +1 (2 points) f) C1 (2 points)
10. (ok to put variable declaration before nested for loop)
#include <iostream.h>
int main() {
int row;
for (row = 1; row <= 9; row++) {
(2 points C condition; 1 point -update)
// Print the stars
for (int count = 1; count <= row; count++)
(1 point C variable declaration)
(1 point C initialization)
(1 point C condition)
(1 point C update)
cout << "*"; (1 point)
// Print the integers in descending order
for (int num = 10 -row; num >= 1; num--)
(1 point C variable declaration)
(1 point C initialization)
(1 point C condition)
(1 point C update)
cout << num; (1 point)
cout << endl; (2 points) }
return 0;
}
11.
void rotate(int& num1, int& num2, int& num3) {
(2 points C void; 2 points C each of 3 parameters) int temp; (2 points)
temp = num1; (4 points C rotation operations)
num1 = num2;
num2 = num3;
num3 = temp;
}