CS246 Midterm: CS 246 0903-winter09-midterm-ans

100 views4 pages

Document Summary

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; while ( i < limit ) { // can combine with previous line 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; 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.