This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Lab 07. CS100J Spring 08. Practice with assertions and loops Goal of this lab Practice with assertions and loops that process a range of integers. Part of this lab is done on paper. 1. Question on ranges: How many values are in the following ranges? The last one requires a formula in terms of h and k. Remember: in the notation h..k, we require k h1. For example, 5..4 is OK but 5..3 is not allowed. a) 5..6 2 (d) h..h 1 b) 5..5 1 (e) h..h1 c) 5..4 (f) h..k k+1h 2. Each line below asks you to write an assignment. We did the first one for you. Range Want Assignment (a) h..k Assign to k so that the range has 1 element: k= h; (b) h..k Assign to h so that the range has 1 element: h= k: (c) h..k Assign to k so that the range has 0 elements: k=h1; (d) h..k Assign to h so that the range has 0 elements: h= k+1; (e) 0..n1 Assign to n so that the range has 1 element: n= 0; (f) 0..n1 Assign to n so that the range has 0 elements: n= 1; (g) h1..10 Assign to h so that the range has 1 element: h= 11; (h) h+1..10 Assign to h to that the range has 0 elements: h=10; 3. Each line below contains an assertion P, which we know is true. Each line also contains an assertion R, which we would like to be true. In the righthand column, put a Boolean expression that, when true, allows us to conclude that R is true. We have filled in the first one for you. KNOW P: WANT R: Additional info needed (a) x is the sum of 1..n x is the sum of 1..100 n == 100 (b) x is the sum of 1. (n1) x is the sum of 1..100 n==101 (c) x is smallest char in s[0..k1] x is smallest char in s[0..s.length()1] k==s.length()k==s....
View
Full
Document
This homework help was uploaded on 02/20/2009 for the course CS 100 taught by Professor Fan/vanloan during the Spring '07 term at Cornell University (Engineering School).
 Spring '07
 FAN/VANLOAN

Click to edit the document details