Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of this Exercise is to gain practice in the use of a switch statem

ID: 3871657 • Letter: T

Question

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 ifelse 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 use a white wire use a Green wire use a Blue wire Red wire Otherwise use a 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 If flag-2 Print: The wire is Green If flag = 3 Print: The wire is Blue 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

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

  

int flag = 0;

cout<<"Input the value of flag : ";

cin>>flag;

switch(flag)

{

case 1: cout<<" The wire is White";

break;

case 2: cout<<" The wire is Green";

break;

case 3: cout<<" The wire is Blue";

break;

default: cout<<" The wire is Red";

break;

}

return 0;

}

Output:

Input the value of flag : 1
The wire is White

Input the value of flag : 3
The wire is Blue

Input the value of flag : 6
The wire is Red

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote