CSC237 Lab Exercise 6a: Pattern Displays

CSC237 Lab Exercise 6a: Pattern Displays June 17, 2021
CSC237_Lab06a_PatternDisplays_20210617.docx 6/17/2021 1:07 PM page 1 of 4
This lab is an exercise in writing functions that display patterns of characters on the screen.
Due Date
You must submit the source code for the solution to this lab exercise to Moodle by
Thursday, June 24, 2021
in order to receive full credit for this work. You must also demonstrate the solution to the instructor during class,
at the earliest opportunity.
Setting up a Visual Studio Project
If you do not remember the detailed steps for setting up a Visual Studio project, refer to the instructions for the
Introductory Lab Exercise, that we used during the first class.
Programming Exercise
Write a program that allows the user to display specific patterns of characters on the screen. The program must be
structured with an interactive “command loop” similar to the main loop in the Command-loop Sample Program
that was discussed during class. (Feel free to use that program as a guide for setting up the command loop for
this lab exercise.)
The ”main” Function
The “main” function must consist primarily of a loop that inputs single-letter commands from the user, and calls a
separate function to implement each command. The “main” function should also contain a local variable called
“maxWidth”. When the “main” function starts, it sets maxWidth to a global constant called
DEFAULT_MAX_WIDTH.
Interactive Commands
The program must support the following commands:
d Display a DECREASING pattern.
h Display help text.
i Display an INCREASING pattern.
q QUIT (end the program)
w Allow the user to specify the maximum width for the display (default width is 5).
The code for each command must call a function that performs the task of that particular command.
The ‘i’ Command
This command must call a function called displayIncreasingPattern. The displayIncreasingPattern function
must take an integer parameter that indicates the maximum width of the pattern. The function prototype for the
displayIncreasingPattern function is:
void displayIncreasingPattern(int);
CSC237 Lab Exercise 6a: Pattern Displays June 17, 2021
CSC237_Lab06a_PatternDisplays_20210617.docx 6/17/2021 1:07 PM page 2 of 4
The INCREASING pattern begins with a single plus sign (‘+’) on a line. The next line of the display has two
plus signs. Each successive line has one more plus signs than the previous line, until the maximum display is
reached. (The default value for the maximum is 5.) For example, if the current maximum is 5, then the output for
the “i” command is shown below:
+
++
+++
++++
+++++
The ‘d’ Command
This command must call a function called displayDecreasingPattern. The displayDecreasingPattern function
must take an integer parameter that indicates the maximum width of the pattern. The function prototype for the
displayDecreasingPattern function is:
void displayDecreasingPattern(int);
The DECREASING pattern begins with the maximum width. Each successive line has one fewer plus signs than
the previous line, until the last line displayed has only one plus sign. For example, if the current maximum is 5,
then the output for the “d” command is shown below:
+++++
++++
+++
++
+
The ‘w’ Command
This command must call a function called setMaxWidth. The setMaxWidth function must take an integer
reference parameter. The variable named as the reference parameter must be the maximum width variable that
controls the maximum width of the display pattern. The function prototype for the setMaxWidth function is:
void setMaxWidth(int&);
CSC237 Lab Exercise 6a: Pattern Displays June 17, 2021
CSC237_Lab06a_PatternDisplays_20210617.docx 6/17/2021 1:07 PM page 3 of 4
Sample Output
The following table contains text that represents a possible execution session for the completed program. (In this
example, what the user types is shown in bold. The purpose of this is to assist the reader of this document to
distinguish text that the user entered from text that the program printed. When the program actually runs, text that
the user types will appear in the same text format as the output.)
Sample Interactive Session
Enter single-letter command (or ‘h’ for help): h
Supported commands:
d decreasing display.
h print this help text.
i increasing display
q quit (end the program).
w set display width.
Enter single-letter command (or ‘h’ for help): i
+
++
+++
++++
+++++
Enter single-letter command (or ‘h’ for help): d
+++++
++++
+++
++
+
Enter single-letter command (or ‘h’ for help): w
Enter desired max width 12
Enter single-letter command (or ‘h’ for help): i
+
++
+++
++++
+++++
++++++
+++++++
++++++++
+++++++++
++++++++++
+++++++++++
++++++++++++
Enter single-letter command (or ‘h’ for help): d
++++++++++++
CSC237 Lab Exercise 6a: Pattern Displays June 17, 2021
CSC237_Lab06a_PatternDisplays_20210617.docx 6/17/2021 1:07 PM page 4 of 4
Sample Interactive Session
+++++++++++
++++++++++
+++++++++
++++++++
+++++++
++++++
+++++
++++
+++
++
+
Enter single-letter command (or ‘h’ for help): q
Are you sure that you want to exit the program? y
Exit the program.
Submit and Demonstrate the Working Program
• Submit the source code file (*.cpp) for the working program to Moodle assignment for this Lab
Exercise.
• Demonstrate the working program to the instructor during class.
• Be sure to save a copy of the source file (*.cpp) in a safe place for future reference.
Always remember: make small, incremental changes. Test each small change as you go.

CSC237 Lab Exercise 6a: Pattern Displays

CSC237_Lab06a_PatternDisplays_20210617 (2)

APA

Click here for further assistance on this assignment

The post CSC237 Lab Exercise 6a: Pattern Displays appeared first on Apax Researchers.

Reference no: EM132069492

GET HELP WITH YOUR PAPERS

GET THIS ANSWER FROM EXPERTS NOW

WhatsApp
Hello! Need help with your assignments? We are here
Don`t copy text!