Starting from:
$29.99

$23.99

Lab #10 Solution

Objectives:

use a switch/case statement
create a void function
call a void function without an argument
call a void function with an argument
Tasks:

Write a program that gives the user 2 menu options: either call a function that will print a greeting and your name 4 times or call a function that will count down from 10 to 0 and then print "Blastoff!". Both functions should use for loops to print the appropriate output.
Write a program that prints 5 bar graphs with asterisks like shown in the example at the bottom of the page. A function that accepts the length (number of asterisks) should be created and then called 5 different times to print the graphs. Use input validation to make sure that a user enters a positive number that is less than or equal to 50.
Follow these steps for Lab 10:

Create a new file named YourLastNameLab10-Menu.c.
In the main function, display a prompt (like shown in the first 2 examples below the instructions) asking the user to choose 1 of 2 options. If the user does not enter 1 or 2, repeat the prompt until they do. Please avoid calling the main() function recursively to accomplish this behavior.
If the user does choose 1 or 2, use a switch/case statement to evaluate the user's choice and call an appropriate function.
If the user chooses 1, call a descriptively-named function that uses a for loop to print Hi, my name is Chris four times. Be sure to use your own first name.
If the user chooses 2, call a descriptively-named function that uses a for loop to print the numbers 10 to 0 each on a new line, followed by Blastoff!
Take a screen clipping of the program that shows the output generated if the user chooses the first option, and paste the image in a Word document named YourLastNameLab10. Take a screen clipping of the second option and paste that in the Word document as well.
Create a new file named YourLastNameLab10-Graphs.c.
Prompt the user and get the lengths (number of *) for each of 5 graphs. If a user doesn't enter a positive number less than or equal to 50, repeat the prompt until they do.
Create a function that accepts an integer value representing the amount of asterisks to print. Only 1 value should be passed to the function. Use a for loop inside the function to print the number of asterisks that corresponds to the number passed to the function.
After valid numbers have been entered for all 5 chart lengths, use appropriate statements to print the numeric length of the chart and the number of asterisks like shown in the example at the bottom of the page.
Take a screen clipping of the program that shows the input and output of the 5 graphs, and paste the image in the Word document named YourLastNameLab10.
Upload and submit the completed YourLastNameLab10-Menu.c file, the YourLastNameLab10-Graphs.c file, AND the YourLastNameLab10 Word file to the appropriate Desire2Learn Dropbox folder.
Example 1 - Menu:

What would you like to do?

  1. Print my name

  2. Count down from 10

 

Choice: 1

 

Hi, my name is Chris

Hi, my name is Chris

Hi, my name is Chris

Hi, my name is Chris

Example 2 - Menu:

What would you like to do?

  1. Print my name

  2. Count down from 10

 

Choice: 2

 

10

9

8

7

6

5

4

3

2

1

0

Blastoff!

Example 3 - Graphs

How long is chart 1? 7

How long is chart 2? 9

How long is chart 3? 8

How long is chart 4? 11

How long is chart 5? 2

 

1.  7|*******

2.  9|*********

3.  8|********

4. 11|***********

5.  2|**

 

More products