=========================preview======================
(comp102)[2007](f)midterm~plliu^_10120.pdf
Back to COMP102 Login to download
======================================================
HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY
COMP 102: Computer and Programming Fundamentals I
Fall 2007
Midterm Examination Solution
October 29, 2007, 6:30 - 8:30 PM
Student Name: _______________________ Lecture Section: __________________
Student ID: _______________________ Lab Section: __________________
INSTRUCTIONS
1.
This is a closed-book, closed-notes examination.
2.
Check that you have total EIGHT questions on all 14 pages
(including this cover page and the last 4 blank pages for rough work).
3.
Write your name, student ID, lecture and lab sections on this page.
4.
Answer all questions using spaces provided, in blue or black ink (no pencil).
5.
All code described in the questions are ANSI C++ compliant.
6.
Turn off your mobile phone/pager or else you will be immediately disqualified.
7.
No calculator is allowed for this exam.
For T.A. use only
Question
Maximum Points
Your Points
1
10
2
12
3
12
4
17
5
10
6
20
7
11
8
8
TOTAL
100
1.
(TOTAL 10 POINTS) Indicate whether the following statements are true or false by circling T or F. You get 1 point for each correct answer.
T a) The following code will give a compilation error.
const char My_Char;
T b) The following code will give a compilation error.
double x = 43; cout << x % 7;
T c) You can always convert a while loop to a for loop.
F d) You can always convert an if-else statement to a switch statement.
F e) In a switch statement, the default case must appear last among all cases.
Otherwise, it would result in a compilation error.
T f) In a switch statement, no two cases can have the same value.
F g) The following expression is always true, given const int PI = 3.14;
( PI * 3.14 / 4 == PI * PI * 0.25 )
F h) All functions must be defined before where it is called in the program.
T i) In C++ programs, it is legal to have repeated function prototypes.
F j) The following code will give a compilation error.
int main( ) { int main = 1; return main; }
2.
(TOTAL 12 POINTS) What is the value of each of the following expressions? Each expression should be evaluated independently with the same set of initial values as given below.
int a = 1;
double d = 1.0;
Mark your answers in the space provided after each expression. If the expression is a Boolean expression, then mark your answer to the Boolean expression with either true or false.
a)
5 + 5 * 2 % a-- __________5_________
b)
4 + 4 * 5 % (++a + 1) __________6___________
c)
1.0 + 1.5 * 3 + (++d) ________7.5______________