{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm2004_fall_sol

# midterm2004_fall_sol - November 1 2004 COMP 102 Midterm...

This preview shows pages 1–6. Sign up to view the full content.

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

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

View Full Document
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_______________
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: (c>='A')&&(c<='Z') b) character c is either an alphabet (upper case or lower case) or a digit. Answer: ((c>='A')&&(c<='Z'))||( (c>='a')&&(c<='z'))|| ( (c>='0')&&(c<='9')) 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 . Answer: (die1>=lowGuess)&& (die2>=lowGuess)&& (die3>=lowGuess) e) die1 is even and die2 is larger than die3. Answer:(die1%2==0)&&(die2>die3)

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

View Full Document
November 1, 2004 COMP 102 -- Midterm Exam Page 4 of 13 3. (12 points in total) Consider the following definition: int fun (int x, int& y){ 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 8 25 6 20 Cout<<fun(3,z);
November 1, 2004 COMP 102 -- Midterm Exam Page 5 of 13 4 (14 points) a) What is the value of variable a after executing each of the following code segment?

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern