Overview
For this assignment you will be building two main components. A menu system and several drawing routines.
The menu system will operate on a whitelist principle and prompt the user for the type of drawing they want and its size. A whitelist is a list of accepted inputs with anything not on the list rejected.
The drawings will all be ASCII shapes of user specified size.
Menu System
The menu should prompt the user for a command and if it is not a valid command, respond it is invalid and prompt again. The commands it needs to respond include:
- help - This will print a list of all accepted inputs and re-prompt the user.
- quit - This will terminate the program.
- square - This will initiate the square drawing.
- box - This will initiate a box drawing.
- diagonaldown - This will initiate a diagonal down line.
- diagonalup - This will initiate a diagonal up line.
- checkerboard - This will initiate a checkerboard pattern.
The matching for the commands should be case insensitive. That is "Help", "help", and "hElP" will all trigger the help command.
Drawings
There are several drawings that your program needs to support
Square
When a square is drawn it will first prompt the user for a size. Valid sizes are 1 through 15 inclusive. An example square of size 5 is
*****
*****
*****
*****
*****
Box
When a box is drawn it will first prompt the user for a size. Valid sizes are 3 through 15 inclusive. An example box of size 5 is
*****
* *
* *
* *
*****
Diagonal Down
When a diagonal down line is drawn, it will first prompt the user for a size. Valid sizes are 3 through 15 inclusive. An example line of size 5 is
*
*
*
*
*
Diagonal Up
When a diagonal up line is drawn, it will first prompt the user for a size. Valid sizes are 3 through 15 inclusive. An example line of size 5 is
*
*
*
*
*
Checkerboard
When a checkerboard drawn, it will first prompt the user for a size. Valid sizes are 5 through 15 inclusive. An example line of size 10 is
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Tips
- Write your program iteratively. You shouldn't ever write more than a few lines of code without compiling and testing it.
- Start with small pieces. It isn't reasonable to sit down and write the whole program from beginning to end. The pieces you build should ultimately fit together to build the whole program.
- It is easiest to draw the various shapes using nested for loops.
- One way to build the program is as follows:
- Write a function that accepts user input and validates it against the list of command. Start with it being case sensitive and then add case insensitivity.
- Write the functionality to print out a help message, quit, and re-prompting the user on invalid input.
- Start with one of the drawings, say a square. Create a function to draw a square. Initially make it draw a fixed size, then allow for it to draw an arbitrary size.
- Write a function to prompt the user for a size within a specified range. This function should validate the input is in the specified range and re-prompt if it is outside. Make sure to write this function so that it can be used for multiple drawings which may have different size constraints.
- Integrate your size prompt function to fully draw your first chosen shape.
- At this point your program should have close to full functionality, with the only thing missing being other shapes.
- Add the remaining shapes to the program using the infrastructure you have already built.
Example Output
User input is in bold
Please enter a command: bad
Invalid command
Please enter a command: hElP
Acceptable commands: help, quit, square, box, diagonaldown, diaonalup, checkerboard
Please enter a command: square
Please enter a size between 1 and 15: -1
The value -1 is not in a valid range.
Please enter a size between 1 and 15: 16
The value 16 is not in a valid range.
Please enter a size between 1 and 15: 5
*****
*****
*****
*****
*****
Please enter a command: box
Please enter a size between 3 and 15: 2
The value 2 is not in a valid range.
Please enter a size between 3 and 15: 5
*****
* *
* *
* *
*****
Please enter a command: diagonaldown
Please enter a size between 3 and 15: 7
*
*
*
*
*
*
*
Please enter a command: diagonalup
Please enter a size between 3 and 15: 7
*
*
*
*
*
*
*
Please enter a command: checkerboard
Please enter a size between 5 and 15: 13
* * * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * * * *
Please enter a command: quit
PreviousNext