midterm2004_fall_sol

Midterm2004_fall_sol - November 1 2004 COMP 102 Midterm Exam Page 1 of 13 THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY Department of Computer

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
November 1, 2004 COMP 102 -- Midterm Exam Page 1 of 13 THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY Department of Computer Science COMP 102: Computer and Programming Fundamentals I Fall 2004 Midterm Examination Ren Lan Liao ManLi Zhu Date: November 1, 2004 Time: 7:30-9:30 pm This exam contains 9 questions in 13 pages. Please count the pages. You have 2 hours to complete this exam. Problem Your point s Max point s Problem Your point s Max point s 1 10 6 12 2 15 7 5 3 12 8 12 4 14 9 12 5 8 Subtotal 59 Subtotal 41 Your total points 100 Please identify yourself: Lab section Name Student id Signature
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
November 1, 2004 COMP 102 -- Midterm Exam Page 2 of 13 1. (10 points) int a = 2, b = 3, c = 4; double d = 8.4, e = 7.0, s = 12.3, t = 2.4; int x = 16, y = 10, z = 27; What is the value of each of the following expressions? (Each expression should be evaluated with the same set of initial values as given above.) a) e / y _________0.7___________________ b) a * b / c + d _________9.4___________________ c) t / b + a / b * z ___________0.8_________________ d) z / b * a / b * b ____________18______________ e) z % b * a / b * z _____________0_______________ f) (int)(s / e) _____________1_______________ g) y / (double)b ____________3.3333________________ h) a * (b + 1) % c ________________0_______________ i) x++ + y _________________26______________ j) x-- + y % ++b ________________19_______________
Background image of page 2
November 1, 2004 COMP 102 -- Midterm Exam Page 3 of 13 2. (15 points) Write expressions that represent the given English expressions. You can assume the following condition: int die1, die2, die3, highGuess, lowGuess; char c; a) character c is an upper case alphabet Answer: b) character c is either an alphabet (upper case or lower case) or a digit. c) Among die1, die2, die3, at least one of them is smaller than highGuess. Answer: (die1<highGuess)|| (die2<highGuess)|| (die3<highGuess) d) Among die1, die2, die3, each one of them is higher or equal to lowGuess . e) die1 is even and die2 is larger than die3. Answer:(die1%2==0)&&(die2>die3)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COMP 102 -- Midterm Exam Page 4 of 13 3. (12 points in total) Consider the following definition: y++; return ( x + 3*y); } What value is assigned to y in question 1-5? 1. int z = 3; int y = fun(2, z); 2. int z = 0; int y = 2 + fun(3,z); 3. int z = 1, t = 6; int y = fun(3* t + 1, z); 4. int z = 5; int t = fun(3,z); int y = z; 5. int z = 3, t=1; int y = fun(fun(2,t),z ); 6. Write a statement to cout the result of fun with argument 3 and z;. 14
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/30/2010 for the course COMP COMP102 taught by Professor Lrr during the Fall '09 term at HKUST.

Page1 / 13

Midterm2004_fall_sol - November 1 2004 COMP 102 Midterm Exam Page 1 of 13 THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY Department of Computer

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online