=========================preview======================
(COMP102)[2003](f)midterm1~3064^_10113.pdf
Back to COMP102 Login to download
======================================================

THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY
Department of Computer Science

COMP 102: Computer and Programming Fundamentals I
Fall 2003
Midterm Examination (All Sections)
Date: 24 October, 2003

This exam contains 10 questions on 11 pages. Please count the pages.
You have 2 hours to complete this exam.

Instructions

1.
This is a closed-book, closed-notes examination.


2.
Check that you have all 11 pages (including this cover page).


3.
Write your name, student number, lecture and lab sections on this page.


4.
Answer all questions in the box provided using a ball point pen.


5.
Please turn off your mobile phone/pager or else you will be disqualified.


6.
No electronic devices (including calculators, PDA, dictionaries, etc.)





Problem
Your points
Max points
Problem
Your points
Max points

1

5
6

8

2

5
7

11

3

10
8

10

4

20
9

8

5

12
10

11








Subtotal

52
Subtotal

48

Your total points
100








Please identify yourself: Lab section

Name

Student Id

Signature






1. (5 points) Which of the following lines contains a valid C++ identifier?
(Write True or False in the corresponding boxes).

A. SHENZHOU#5

B.
SHEN_ZHOU_5




C.
SHENZHOU5!




D.
Oct_24_2003




E.
24_Oct_2003






2. (5 points) Given

int a = 1, b = 4, c = 6, d = 2, x = 2, y = 3, z = 2 ;

What is the value of each of the following expressions?

a) (4 + 5 * a >= b C 4) || (c C 8)_______true_______


b) c%x || b == 9/z && (d C 3) ________true_______


c (c / d ) && (y > 5/2) ________true________


d) a/b + y-- ________3___________


e) ++x - --z ________2___________



False

True

True

False

False

3. (10 points)
What is the value of n after each of the following C++ statements are executed?


a) int n = 0;
if(!n)
n = n + 2;
if(n)
n = -n;
n = n + 2000;


Answer: 1998


b) int n=1, a=4, b=6, c=8;
if(a < 3 || b>5 && c<9)
n = n + 15;


Answer: 16


c) int m=4, n=5, i=0, k=3;
if(m>=0) if(k<=10) if(i>0) n=2; else if(n<4) n=3;
else n=113; else n=105; else n=102;


Answer: 113


d) int n = 1;
while ( n < 11 )
if(n%3)
n = n+2;
else
n = n+4;


Answer: 13


e) bool n = 2+4*2==12||4>6==2>3&&!false;


Answer: true
4. (20 points total)
a) (5 points) What is the output of the following program?
#include <iostream.h>
int main(){
int sum, j, i = 1;
while