First Summer 2006


Homework Ten: Last Homework Assignment.
Due date
Monday June 12, 11:59pm
Late policy
Please turn everything on time, late solutions will not be accepted.

Work policy
Working in groups is encouraged but please turn in your own version of the assignment.

Also, please make sure you

with the Computer Science Department's Statement on Academic Integrity before turning in your assignment.

Task
There are two problems in this assignment:

  1. Write a program that prints a scalable pattern as illustrated below.

    Enter size of matrix: 12
    * * * * * * * * * * * *
    * * * * *     * * * * *
    * * * *         * * * *
    * * *             * * *
    * *                 * *
    *                     *
    *                     *
    * *                 * *
    * * *             * * *
    * * * *         * * * *
    * * * * *     * * * * *
    * * * * * * * * * * * *
    Enter size of matrix: 16
    * * * * * * * * * * * * * * * *
    * * * * * * *     * * * * * * *
    * * * * * *         * * * * * *
    * * * * *             * * * * *
    * * * *                 * * * *
    * * *                     * * *
    * *                         * *
    *                             *
    *                             *
    * *                         * *
    * * *                     * * *
    * * * *                 * * * *
    * * * * *             * * * * *
    * * * * * *         * * * * * *
    * * * * * * *     * * * * * * *
    * * * * * * * * * * * * * * * *
    Enter size of matrix: 24
    * * * * * * * * * * * * * * * * * * * * * * * *
    * * * * * * * * * * *     * * * * * * * * * * *
    * * * * * * * * * *         * * * * * * * * * *
    * * * * * * * * *             * * * * * * * * *
    * * * * * * * *                 * * * * * * * *
    * * * * * * *                     * * * * * * *
    * * * * * *                         * * * * * *
    * * * * *                             * * * * *
    * * * *                                 * * * *
    * * *                                     * * *
    * *                                         * *
    *                                             *
    *                                             *
    * *                                         * *
    * * *                                     * * *
    * * * *                                 * * * *
    * * * * *                             * * * * *
    * * * * * *                         * * * * * *
    * * * * * * *                     * * * * * * *
    * * * * * * * *                 * * * * * * * *
    * * * * * * * * *             * * * * * * * * *
    * * * * * * * * * *         * * * * * * * * * *
    * * * * * * * * * * *     * * * * * * * * * * *
    * * * * * * * * * * * * * * * * * * * * * * * *
  2. (Problem 8 in Lecture Notes Eighteen):

    Consider the guess my number game of chapter 3.

    Write a program in which

    • the player and the computer trade places in the number guessing game.
    • That is, the player picks a random number between 1 and 100
    • that the computer has to guess.

    Before you start think about how you guess.

    That's what the computer program should do.

Here's how my program runs (my answers are in red):

Please think of a number between 0 and 100, then press enter. I will guess your number. # I choose 67
I know the number is between 0 and 100 my guess is: 50
How is my guess no.1?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too low
I know the number is between 50 and 100 my guess is: 75
How is my guess no.2?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too high
I know the number is between 50 and 75 my guess is: 62
How is my guess no.3?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too low
I know the number is between 62 and 75 my guess is: 68
How is my guess no.4?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too high
I know the number is between 62 and 68 my guess is: 65
How is my guess no.5?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too low
I know the number is between 65 and 68 my guess is: 66
How is my guess no.6?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Too low
I know the number is between 66 and 68 my guess is: 67
How is my guess no.7?
  [1] Too low
  [2] Too high
  [3] Correct
Answer: Correct
See, I have guessed it in only 7 tries.

Grading
Feedback will be provided within a week, grades will be posted on-line.