# 2009sol - APSC 160: SAMPLE MIDTERM EXAMINATION SOLUTIONS...

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

APSC 160: SAMPLE MIDTERM EXAMINATION S OLUTIONS Don't even think about looking at these solutions unless you've put serious effort into coming up with your own solution. Reading a solution that someone else put together is easy and, in itself, will not prepare you for the midterm exam. You need to be able to come up with these solutions on your own! Note: 1) Many people lost marks on Q4A because they did not read the question. If you do not make use of the printStars function, you will lose marks, even though your solution "works". 2) Many people lost marks on Q4B because they did not follow the hint provided. If your solution does not make use of the function written in Q4A, you will lose marks, even though your solution "works". 3) Many people lost marks on Q5B and Q5C because they did not make use of the symbolic constants provided. 4) Many people lost marks on Q5C because they did not make appropriate use of if-else statements and/or their solution incorporated redundant Boolean expressions.

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

View Full Document
Page 2 of 10 Section 1: Multiple Choice For each of the multiple choice questions below, circle the letter corresponding to the one right answer. [2] Q1A. Consider the following code segment: if( num1 < 2 || num2 > 7 ) printf( "A" ); if( num2 > 9 ) printf( "B" ); else printf( "C" ); What is printed on the screen when this code segment runs assuming that num1 and num2 are variables of type int and that num1 has the value 4 and num2 has the value 8? a) B b) C c) A d) AB e) AC [3] Q1B. Consider the following code segment: int count = 1; int sum = 0; while( count < 6 && sum < 7 ) { sum += count; count++; } printf( "sum = %d, count = %d\n", sum, count ); What is printed on the screen when this code segment runs? a) sum = 10, count = 5 b) sum = 15, count = 6 c) sum = 15, count = 5 d) sum = 10, count = 4 e) none of the above 1 mark was awarded if you answered d) rather than a). In that case you got the sum right but the count wrong. There were no marks for choosing b), c) or e).
Page 3 of 10 [2] Q1C. What is the value of count after the following code segment has executed? int count = 0; int indexA; int indexB; for( indexA = 0; indexA < 4; indexA++ ) { for( indexB = 3; indexB >= 0; indexB-- ) count++; } a) 3 b) 4 c) 9 d) 12 e) none of the above [2] Q1D. Suppose you want to write a function that takes an array of integers and the size of that array as parameters and that prints all the entries in the array onto the screen. What is the

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.

## This note was uploaded on 03/18/2010 for the course APSC APSC 160 taught by Professor Jeremyhiliker during the Spring '08 term at The University of British Columbia.

### Page1 / 10

2009sol - APSC 160: SAMPLE MIDTERM EXAMINATION SOLUTIONS...

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

View Full Document
Ask a homework question - tutors are online