=========================preview======================
(COMP104)midterm06.pdf
Back to COMP104 Login to download
======================================================
The Hong Kong University of Science and Technology
COMP104: Programming Fundamentals and Methodology

Fall 2006, Lecture Section 1, 2, 3
Midterm Examination
Monday, October 16, 2006 7:00 C 9:00PM

Student Name: Lecture Section:
Student ID: Lab Section/TA Name:
Instructions:
1.
This is a closed-book, closed-notes examination.

2.
Check that you have all 14 pages (including this cover page, one blank page for answering question 5, and the last 2 blank pages for rough work).

3.
Write your name, student ID, lecture section, lab section/TA name on this page.

4.
Answer all questions using the space provided after each question.

5.
Rough work should be done on the last blank page provided.

6.
Unless otherwise stated, all programming language constructs described in the questions are C++s.


Question Score
1 / 10
2 / 12
3 / 15
4 / 16
5 / 13
6 / 20
7 / 16
Total* / 102

* The total score of this exam paper may NOT be exactly 100.
Indicate whether the following statements are true or false by circling the answer. You get 1 mark for each correct answer, but C1 mark for each wrong answer, and 0 mark if you do not answer. (Remark: statistically speaking, it is unwise to guess if you dont know the answer.)
[ True / False ] a) C++ is the first object-oriented programming language in humans history.
FALSE
[ True / False ] b) A compiler translates source code to assembly code.
FALSE or TRUE are both acceptable
[ True / False ] c) The following 2 output statements have the same printout:
1.
cout << A;


2.
cout << A;



TRUE

[ True / False ] d) Any switch statement can be rewritten as an equivalent concatenated if-else-if statement.
TRUE
[ True / False ] e) A Boolean (or logical) expression with one or more logical-OR operators || can always be rewritten into an equivalent Boolean (or logical) expression with NO logical-OR operator.
TRUE
[ True / False ] f) One if-else statement can always be rewritten by using one if-else operator in C++.
FALSE
[ True / False ] g) Each identifier in a C++ enumeration type declaration must be represented internally by a different integer.
FALSE
[ True / False ] h) The continue statement can only be used inside a do/while/for loop statement.
TRUE
[ True / False ] i) The break statement can only be used inside a do/while/for loop statement.
FALSE
[ True / False ] j) The following statement is a legal C++ variable definition: int ___; // NOTE: ___ consists of 3 underscores with no space in between.
TRUE
a) [2 marks] If the subtraction operator - is right associative, what is the value of the following expression: 20-2-15-3?
30
b) [6 marks] What are the values of x, y, and z after the following C++ statements are executed?
int a = 2.5, b = 7.5;
int x = 2.5 + 7.5 / a;
double y = a + b * 1.0 / a;
double z = b / a + b / (double)a +