Control Structures
Due 11:59pm Monday Sept 25
-
Do program design exercise 11 in Chapter 3 of the text.
Solution.
-
Do program design exercise 16 in Chapter 3 of the text.
Solution.
-
Write a program to generate a histogram, as follows:
 |
Have the user input a sequence of numbers between 0 and 99,
using any negative number as the "sentinel" that ends the sequence. If a
non-negative number is outside the range 0-99, ignore it and ask the user to try
again.
|
 |
Keep track of how many numbers are between 0 and 9, 10 and 19,
20 and 29, and so on, up to 90 and 99. (Hint 1: use a different variable for each
bin. Hint 2: use the && operator discussed
in class to form the logical "and" of two conditions).
|
 |
Then print a histogram that shows how many numbers
occurred in each bin. For example, suppose there were 4, 5, 7, 3, 0, 4, 6,
8, 9, and 2 numbers in each of the 10 bins, respectively. Then the output should look like
this:
0- 9: ****
10-19: *****
20-29: *******
30-39: ***
40-49:
50-59: ****
60-69: ******
70-79: ********
80-89: *********
90-99: **
(Hint 3: Define a method to print the *'s.)
Solution.
|
|