Question: HELP PLEASE!! Patterns Write a program that can create 4 different patterns of varying sizes. The size of each pattern is determined by the number
HELP PLEASE!!
Patterns
Write a program that can create 4 different patterns of varying sizes. The size of each pattern is determined by the number of columns or rows. For example, a pattern of size 5 has 5 columns and 5 rows. Each pattern is made of the character * and a digit, which shows the size. The size must be between 5 and 9.
Here are the four patterns in size 5:
| Pattern 1 | Pattern 2 | Pattern 3 | Pattern 4 |
| *5555 | ***** | 55555 | 5555* |
| 5*555 | *555* | 5***5 | 555*5 |
| 55*55 | *555* | 5***5 | 55*55 |
| 555*5 | *555* | 5***5 | 5*555 |
| 5555* | ***** | 55555 | *5555 |
Your program must display a menu and ask the user to choose a pattern and size. Please note that your program must be robust; it must prompt the user to choose an option only between 1 and 5 and a pattern size only between 5 and 9. Use data validation loops to make sure that a number in the appropriate range is entered for both the option and the pattern size.
A sample menu, with sample user input is shown below:
M E N U
1. Pattern One
2. Pattern Two
3. Pattern Three
4. Pattern Four
5. Quit
Enter Option (1 to 5): 11
Option incorrect. Try again.
Enter option (1 to 5): 3
Enter pattern size (5 to 9): 22
Pattern size incorrect. Try again.
Enter Pattern Size (5 to 9): 7
Use separate functions to get the option, get the size, and to print each pattern. Be sure to pass the size into the pattern functions. When your program has processed the first user option, it should loop back around to re-print the menu, read another option from the user, process it, and so on, until the user enters 5, which should cause the program to stop.
Each pattern must be printed using a set of nested loops. The functions to print the patterns must use some sort of method to recognize when to print the number that is the size and when to print the *. The following function prints Pattern 1 for any size. Note that as we study the pattern, we see that when the row and column are equal, the * is printed but for all other locations in the pattern, size is printed.
void pattern1(int size)
{
int row, col;
// loop through the rows
for (row=0; row < size; row++)
{
// print one row
for (col=0; col < size; col++)
{
if (row == col) printf(*);
else
printf(%c, size); }
printf( );
}
}
To determine the logic needed for the rest of the patterns, it may be helpful to draw a grid on a piece of paper, including the row and column number of each cell. Put the pattern into the cells, then look for something consistent for all *s and for all numbers and code this into your function. Hint: For Pattern 4, consider the sum of the row and column number for each cell.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
