15-100: Introductory/Intermediate Programming (Section F)
Fall 2006
Exercise    - practice
11/03/2006
Practice Loops and other items
Due:  none

Assignment:  (worth 0 exercise points - this exercise is for practice only)




1)  Write a program that has three robots placed in random positions on the screen.

Ask the user how many times the three robots should move forward.  All three robots should move forward that number of times.   Then, ask how many beepers to put down.  All three robots should put down that many beepers.   If the robots don't have enough beepers, put a message to the screen and continue.  All three robots then turn left.  NO ERROR SHUTOFF SHOULD OCCUR at any time, so guard against it.

a)  Have the previous paragraph's behavior happen 10 times.  (use a loop to shorten this)

b)  Instead, ask the user how many times to do this.

c)  Instead of a set number of times, after each round, ask the user if they want to do it again. 


2)  Write a program that writes the numbers 1 - 60 on the screen, in three columns.   The numbers 1 through 20 should appear in the first column, the numbers 21-40 should appear in a second column (perhaps column 35&36 on the screen), and the numbers 41 - 60 should appear in a third column (perhaps column 70&71 on the screen).


3)  a)  Write a program which allows the user to enter a list of course percentages (0 - 100).    When the user has finished entering scores, the program should report how many A's were achieved (according to the percentages for this course).   Your program should handle as many scores as the user wishes to enter.  

b)  Modify the program in part a to print out a table of counts for each of the letter grades.   For instance:
Sample Input:    100  90  80  81  78  73 95  55
Sample Output:
A    3
B    2
C    2
D    0
F    1


4)   Write a program that generates 100 random numbers less than 10,000.  The program should report:
 - how many of those numbers were even
 - how many of those numbers were odd

5)  a) Ask the user to enter the name of a movie.   The program should then:
- report the number of vowels in the name of the movie.
- display the movie, with every other word being in all caps.  EG:  the PHANTOM of THE opera
b)  Let the user do this repeatedly (put it in a loop).   The program will stop when the user types QUIT.

6)  a) Ask the user to type in the name of 10 movies.  Afterwards, the program should display which movie had the longest  name.
b) Don't restrict the user to 10 movies.  Let them type in as many movies as they want.  They can indicate that they are done by typing the word QUIT.


7)  Ask the user to type in the name of 10 movies.  Afterwards, the program should display the following:
a)  all movies that have less than 25 characters inthe name
b)  all movies that have only one word in the name
c)  all movies that begin with a vowel
d)  the name of the movie with the most WORDS in its name

8)  Write a program that reads a number from the user.  The program should then display a box of  X's, 6 columns wide, with the number of rows indicated by the number entered.   For instance:  the numbers 3, 4 and 6 should produce:

XXXXXX            XXXXXX           XXXXXX
XXXXXX            XXXXXX           XXXXXX
XXXXXX            XXXXXX           XXXXXX
                  XXXXXX           XXXXXX
                                   XXXXXX
                                   XXXXXX


9) Write a program that reads a number from the user.  The program should then display a box of  X's, 6 rows high, with width indicated by the number entered.  For instance:  the numbers 3, 4 and 6 should produce:

XXX            XXXX            XXXXXX
XXX            XXXX            XXXXXX
XXX            XXXX            XXXXXX
XXX            XXXX            XXXXXX
XXX            XXXX            XXXXXX
XXX            XXXX            XXXXXX


10)  Write a program which asks the user for two numbers, the first being the width of the box, the second being the height.  So for instance, the numbers 3 and 4 should produce:

XXX
XXX
XXX
XXX


11) Write a program which reads two numbers from the user.  The first number is a width and the second is a height.  Display a box of X's with O's around the outside border.  For instance, the numbers 3 and 4 should produce:

OOOOO
OXXXO
OXXXO
OXXXO
OXXXO
OOOOO


12)  Write a program which asks the user for a number.   A "triangle" of stars is then displayed of height indicated by the number.  A "triangle" of n stars is defined as n rows of *'s where the i'th row has i stars in it.  For instance:
Triangle of 3:                Triangle of 4:
*                                   *
**                                  **
***                                 ***
                                    ****


13)  Write a program that asks the user for a number.   The program should then draw a tree of *’s of height of that number.   For instance, if the user typed in 4, the program should display:
          *
         * *
        *   *
       *******
Center the tree horizontally on the screen.



Handin:
  • None.