Solved CSC150 Computer Science 1 Programming Assignment 5 Loops

$30.00

Original Work ?

Download Details:

  • Name: P5-150-Patterns-Menu-program-kxwnbc.zip
  • Type: zip
  • Size: 2.49 MB

Category: Tags: , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

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 10.

 

Here are the four patterns in size 7:

 

Pattern 1 Pattern 2 Pattern 3 Pattern 4
* 7 7 7 7 7 7 * * * * * * * 7 7 7 7 7 7 7 * * * * * * 7
7 * 7 7 7 7 7 * 7 7 7 7 7 * 7 * * * * * 7 * * * * * 7 *
7 7 * 7 7 7 7 * 7 7 7 7 7 * 7 * * * * * 7 * * * * 7 * *
7 7 7 * 7 7 7 * 7 7 7 7 7 * 7 * * * * * 7 * * * 7 * * *
7 7 7 7 * 7 7 * 7 7 7 7 7 * 7 * * * * * 7 * * 7 * * * *
7 7 7 7 7 * 7 * 7 7 7 7 7 * 7 * * * * * 7 * 7 * * * * *
7 7 7 7 7 7 * * * * * * * * 7 7 7 7 7 7 7 7 * * * * * *

 

 

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 10.  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 10): 12

Pattern size incorrect.  Try again.

Enter Pattern Size (5 to 10): 4

 

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.  Your program must use a single set of nested loops to print each pattern shown above.  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.

Please review Notes Example 18 and the “Menu Driven Program” section of the notes.  Your program should follow a similar format.

 

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, by making a table and putting the row and column numbers on the table, 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(“%2d”, size);        }

printf(“\n”);

}

}

 

Design your program by completing the CSC 150 Program Design Document.  Be sure to include a structure chart for the program, the prototype for each function, and a brief description of each function’s purpose.  Save the design in a file named PatternsDesign_xxx.doc where xxx are your initials and submit it in the Program 5 Design drop box by the date shown in the calendar – this is before the program due date.

 

Code your program.  Save it in a file named patterns_xxx.cpp where xxx are your initials.

 

Compile, run and test your program.

 

Submit your working .c file in the Program 5 drop box by the date shown in the calendar and drop box tools.