{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lab07_ProblemSet

lab07_ProblemSet - Lab07.CS100JSpring08. Goalofthislab ....

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

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 h–1. 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..h–1 0 c) 5..4 0 (f) h..k k+1-h 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=h-1; (d) h..k Assign to h so that the range has 0 elements: h= k+1; (e) 0..n–1 Assign to n so that the range has 1 element: n= 0; (f) 0..n–1 Assign to n so that the range has 0 elements: n= -1; (g) h–1..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. (n–1) x is the sum of 1..100 n==101 (c) x is smallest char in s[0..k–1] x is smallest char in s[0..s.length()–1]

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 ]}

Page1 / 3

lab07_ProblemSet - Lab07.CS100JSpring08. Goalofthislab ....

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

View Full Document
Ask a homework question - tutors are online