Midterm Answers

Midterm Answers - Midterm Answers CS 246 Winter 2009...

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

View Full Document Right Arrow Icon
Midterm Answers – CS 246 Winter 2009 Instructor: Ric Holt February 26, 2009 These are not the only answers that are acceptable, but these answers come from the notes or class discussion. 1. (a) 1 mark False (b) 1 mark False (c) 3 marks int i; i = 0; // Can combine with previous line while ( i < LIMIT ) { cout << i << endl; i += 1; // Or any other way to increment i by 1 } 0: no answer; 1: rough sketch; 2: almost right; 3: correct (d) 3 marks switch ( i ) { case 0: cout << "zero" ; break ; case 5: cout << "five" ; break ; default : cout << "No go" ; } 0: no answer; 1: rough sketch; 2: almost right; 3: correct 2. (a) 1 mark True (b) 3 marks cout << rand() % 3 + 2; // Do not insist upon using srand 0: no answer; 1: rough sketch; 2: almost right; 3: correct (c) 3 marks It is a statement of what is assumed to be true when the associated function is called. It used used to help give the specification (or meaning) of the function. POSSIBLY: It helps in showing that the function is correct. 3: both statements; 2: one statement; 1 rough idea; 0: no answer (d) 3 marks This is a particular way to pass an (actual) argument to a (formal) parameter. The actual value of the argument is passed into a slot (or space or variable) within (the stack frame of) the called function. 3: both stmts; 2: one statement; 1 rough idea; 0: no answer 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
3. (a) 3 marks An assert or assertion statement takes an argument with evaluates to true or false. It is used to document and check the correctness of programs. It records assumptions about the state (of variables and constants) (in a particular location) in the program. 1 mark for each of the above; total 1 mark for rough idea
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2012 for the course CS 246 taught by Professor Wormer during the Winter '08 term at Waterloo.

Page1 / 4

Midterm Answers - Midterm Answers CS 246 Winter 2009...

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

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