CMSC 104, Sect. 0101

Project 2: Patterns

Out: Monday, October 27, 2008
Due: Friday, November 7, 2008, before 11:59 PM


The Objective

This project is designed to give you practice with loops, more complex if/then 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 both the number of rows and the number of columns in the box. You will print one of three 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
 5$$$$   $$$$5   $$$$$
 $5$$$   $$$5$   5$$$$
 $$5$$   $$5$$   55$$$
 $$$5$   $5$$$   555$$
 $$$$5   5$$$$   5555$

You will ask the user to input the size of the box and also the 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 four options. Each option will perform a different task.


Sample Output

linux3[39]% gcc -ansi -Wall proj2.c
linux3[40]% a.out

This program prints boxes in three 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 three
pattern options shown below: A, B, and C.  The
following example shows the patterns for a box of
size 5 (5 rows and 5 columns) and the character '$'

   A       B       C
 5$$$$   $$$$5   $$$$$
 $5$$$   $$$5$   5$$$$
 $$5$$   $$5$$   55$$$
 $$$5$   $5$$$   555$$
 $$$$5   5$$$$   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
Q - Quit

Enter your menu selection: a

5$$$$
$5$$$
$$5$$
$$$5$
$$$$5

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: B

$$$$5
$$$5$
$$5$$
$5$$$
5$$$$

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: c

$$$$$
5$$$$
55$$$
555$$
5555$

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: q

Have a nice day!      

linux3[43]% a.out

This program prints boxes in three 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 three
pattern options shown below: A, B, and C.  The
following example shows the patterns for a box of
size 5 (5 rows and 5 columns) and the character '$'

   A       B       C
 5$$$$   $$$$5   $$$$$
 $5$$$   $$$5$   5$$$$
 $$5$$   $$5$$   55$$$
 $$$5$   $5$$$   555$$
 $$$$5   5$$$$   5555$

Please enter the size: 4
Please enter the character: *

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: a

4***
*4**
**4*
***4

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: b

***4
**4*
*4**
4***

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: C

****
4***
44**
444*

A - Pattern A
B - Pattern B
C - Pattern C
Q - Quit

Enter your menu selection: Q

Have a nice day!      

linux3[44]% 


Submitting the Program

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

linux3[45]% submit cs104_0101 Proj2 proj2.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.

linux3[46]% submitls cs104_0101 Proj2

Last Modified: Monday, 27-Oct-2008 16:00:00 EDT