CMSC104, Spring 2004
Programming Project 5
Patterns
Out: Monday, April 12, 2004
Due: Wednesday, April 21, 2002 before midnight
The Objective
This project is designed to give you practice with nested for loops,
switch statements and characters.
The Task
The program you write will deal with printing patterns. You will plot a
filled-in box using an ascii character and also the number corresponding
to the size of the box. The size of the box will be entered by the user
and will be the both the number of rows and the number of columns in the
box. You will print one of four patterns depending on the menu option the
user selects. For a box of size 5 and the character '$',
the following pattern options could be produced:
A B C D
5$$$$ $$$$5 $$$$$ $$$$$
$5$$$ $$$5$ $$$$5 5$$$$
$$5$$ $$5$$ $$$55 55$$$
$$$5$ $5$$$ $$555 555$$
$$$$5 5$$$$ $5555 5555$
You will ask the user to input the size of the box and also
the ascii character you should use to display the pattern.
For the size, you should only allow the user to enter a number
between 2 and 9, inclusive. So, 1, for example, is not a valid size.
You should error check the input and allow the user to keep entering numbers
until he/she enters a number in the correct range. See the
sample output below.
After getting the user input, you must present a menu to the user. The
menu should have five options. Each option will perform a different task.
- The 'A' option will display Pattern A.
- The 'B' option will display Pattern B.
- The 'C' option will display Pattern C.
- The 'D' option will display Pattern D.
- There should also be a Quit option on the menu. The menu should
continue to display until the users enters a Q for quit. You should
allow the user to enter either upper or lower case menu options
Sample Output
linux3[39]% gcc -ansi -Wall proj5.c
linux3[40]% a.out
This program prints boxes in four different
patterns. The user must specify the size of the
box and also the character with which to print
the box. Depending on the pattern, the box will
be printed with some combination of the character
and also the number corresponding to the size. The
user will be presented with a menu listing the four
pattern options shown below: A, B, C and D. The
following example shows the patterns for a box of
size 5 (5 rows and 5 columns) and the character '$'
A B C D
5$$$$ $$$$5 $$$$$ $$$$$
$5$$$ $$$5$ $$$$5 5$$$$
$$5$$ $$5$$ $$$55 55$$$
$$$5$ $5$$$ $$555 555$$
$$$$5 5$$$$ $5555 5555$
Please enter the size: -5
Invalid size. Must be between 2 and 9.
Enter the size: 10
Invalid size. Must be between 2 and 9.
Enter the size: 0
Invalid size. Must be between 2 and 9.
Enter the size: 5
Please enter the character: $
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: a
5$$$$
$5$$$
$$5$$
$$$5$
$$$$5
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: B
$$$$5
$$$5$
$$5$$
$5$$$
5$$$$
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: c
$$$$$
$$$$5
$$$55
$$555
$5555
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: D
$$$$$
5$$$$
55$$$
555$$
5555$
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: q
Have a nice day!
linux3[43]% a.out
This program prints boxes in four different
patterns. The user must specify the size of the
box and also the character with which to print
the box. Depending on the pattern, the box will
be printed with some combination of the character
and also the number corresponding to the size. The
user will be presented with a menu listing the four
pattern options shown below: A, B, C and D. The
following example shows the patterns for a box of
size 5 (5 rows and 5 columns) and the character '$'
A B C D
5$$$$ $$$$5 $$$$$ $$$$$
$5$$$ $$$5$ $$$$5 5$$$$
$$5$$ $$5$$ $$$55 55$$$
$$$5$ $5$$$ $$555 555$$
$$$$5 5$$$$ $5555 5555$
Please enter the size: 4
Please enter the character: *
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: a
4***
*4**
**4*
***4
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: b
***4
**4*
*4**
4***
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: C
****
***4
**44
*444
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: d
****
4***
44**
444*
A - Pattern A
B - Pattern B
C - Pattern C
D - Pattern D
Q - Quit
Enter your menu selection: Q
Have a nice day!
linux3[44]% a.out
Submitting the Program
Here is a sample submission command. Note that the project name starts
with uppercase 'P'.
submit cs104_0701 Proj5 proj5.c
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show the file that
you submitted in a format similar to the Unix 'ls' command.
submitls cs104_0701 Proj5