Date: Mon, 11 Nov 1996 17:00:42 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Tue, 15 Oct 1996 13:48:57 GMT Content-length: 5080 Program 4

Program 4

For this assignment, you will write a program that is capable of drawing a variety of shapes. The shapes supported by your program include a square, a rectable, an isoscoles triangle, and a diamond. Each shape can be printed "solid" or "hollow" using any desired character.

Your program should be menu-driven, so that the user is repeatedly presented with a menu of their options - the various shapes to print, and the current settings of the options (solid or hollow and printing character).

You should also check for invalid input. If the user enters invalid input, you should display an error message and promt the user to re-enter the information.

Note: In general, code "duplication" is bad - you don't want to have identical or very similar code repeated throughout your program if it isn't necessary. Instead, you should try writing one function which does the job. Often it is necessary to generalize that function by adding more parameters. For this program, you don't need separate hollow and solid printing functions for each of the different shapes! In addition, it is possible to put the valid-input-checking code in one function and avoid duplicating it all over the place.

What to Hand In

You should hand in your source code, and the program's output showing all four shapes being printed in both solid and hollow mode. The overall format of the output should be very similar to the sample output below.

Notes and Hints

Sample Output

Welcome to John Q. Doe's shape-printing program!  Here are your
options:

D - Print a diamond shape   C - Change character (currently *)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? Q
How many rows? 3

   ***
   ***
   ***


D - Print a diamond shape   C - Change character (currently *)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? r
How many rows? 2
How many columns? 12

   ************
   ************


D - Print a diamond shape   C - Change character (currently *)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? C
What character to print with? &

What is your selection? D
What size diamond? 3

     &
    &&&
   &&&&&
    &&&
     &


D - Print a diamond shape   C - Change character (currently &)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? h
Now in hollow mode.


D - Print a diamond shape   C - Change character (currently &)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently hollow)
T - Print a triangle        X - Exit program

What is your selection? T
How many rows? -1

-1 is not a valid size.  Please try again.

How many rows? 5

       &
      & &
     &   &
    &     &
   &&&&&&&&&


D - Print a diamond shape   C - Change character (currently &)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? Z

Z is not a valid menu choice!

What is your selection? c
What character to print with? %

What is your selection? R
How many rows? 4
How many columns? 8

   %%%%%%%%
   %      %
   %      %
   %%%%%%%%


D - Print a diamond shape   C - Change character (currently %)
Q - Print a square          H - Switch between hollow/solid
R - Print a rectangle           (currently solid)
T - Print a triangle        X - Exit program

What is your selection? x
Goodbye!