Answered step by step
Verified Expert Solution
Question
1 Approved Answer
EGR 126 Exercise 5B - switch The objective of this Exercise is to gain practice in the use of a switch statement by write a
EGR 126 Exercise 5B - switch The objective of this Exercise is to gain practice in the use of a switch statement by write a program to perform a similar decision process as in Exercise 5A, but to use a switch statement instead of if and if-else conditionals. Because the switch statement makes decisions on incremental values rather than on ranges, it is easier to use the switch statement with specific values for the flags. The problem can be stated as follows: A circuit diagram requires wires of a certain color to be used in certain areas. A flag value is obtained from a blueprint or wiring diagram. Using the flag value, determine the color of wire: If flag = 1 If flag = 2 If flag = 3 If flag = 4 use a White wire use a Green wire use a Blue wire use a Red wire The following flowchart can also be used to determine the color of wire: Obtain a value for the flag If flag = 1 Print: The wire is White Print: The wire is Green flag = 2 If Print: The wire is Blue flag = 3 else Print: The wire is Red You should use a switch statement to implement the logic (not if or if-else). Test the program with values in each range to make sure it works. For submission, show the output for two runs of the program using values of 2 and 5. Save a copy of your code. You will use it in Exercise 6B. Ex 5B comments: 1) Inclusion of input validation including messages that clearly state what is invalid. This could be done in the input prompt: cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started