Question

In: Computer Science

consider execution of the following switch statement: int Enter = 10; cin >> Enter; switch (Enter)...

consider execution of the following switch statement:

int Enter = 10;

cin >> Enter;

switch (Enter)

{

case 1: Enter = -4;

case 2: Enter = -6;

case 4: break;

case 6: Enter = -8;

break;

default: Enter = -1;

}

What would the value of Enter be after execution of this code if the value read for Enter were 4?

-4,-6,-8 or none

Solutions

Expert Solution

/*

As we are giving 4 as input to Enter value Enter is assigned with 4 so at present, the value of Enter is 4

In switch case, if Enter is 4 we are just breaking the switch so Enter is still 4.

*/

//CODE

#include <iostream>
using namespace std;
int main()
{
int Enter = 10;
cin >> Enter;
  
switch (Enter)
{
case 1: Enter = -4;
  
case 2: Enter = -6;
  
case 4: break;
  
case 6: Enter = -8;
  
break;
  
default: Enter = -1;
  
}
cout << "Enter : " << Enter;
return 0;
}

//OUTPUT


Related Solutions

Determine the execution count of the following programs: (number of loops executed?) int i = 10;...
Determine the execution count of the following programs: (number of loops executed?) int i = 10; while(i > 0) { for(int p = 5; p < 14; p++) b{ System.out.println(i + p) p++; } i--; }
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:                         A         Area of a Circle                         C         Circumference of a Circle                         S          Surface Area of a Sphere                         V         Volume of a Sphere Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use...
What will the following code segments print on the screen? int num = 3; switch (num){...
What will the following code segments print on the screen? int num = 3; switch (num){             case 1:                         System.out.println(“Spring”); case 2:                         System.out.println(“Summer”); case 3:                         System.out.println(“Autumn”); case 4:                         System.out.println(“Winter”); }
Consider the following program written in C syntax: void swap(int a, int b) { int temp;...
Consider the following program written in C syntax: void swap(int a, int b) { int temp; temp = a; a = b; b = temp;} void main() { int value = 2, list[5] = {1, 3, 5, 7, 9}; swap(value, list[0]); swap(list[0], list[1]); swap(value, list[value]); } For each of the following parameter-passing methods, what are all of the values of the variables value and list after each of the three calls to swap? Passed by value Passed by reference Passed...
Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M] void my_recursive_function(int...
Trace the execution of my_recursive_function(100) and my_recursive_function(32) for the following code snippet. [0.5 M] void my_recursive_function(int n) { if(n == 0) { printf("False"); return; } if(n == 1) { printf("True"); return; } if(n%2==0) my_recursive_function(n/2); else { printf("False"); return; } } int main() { my_recursive_function(n); return 0; }
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int n, int k)             if (n <= 0) return 0;             else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));             else return BBOX(n-1,k-2);             Find BBOX(8, 5)
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a)     Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. (b)     Draw a Gantt chart showing preemptive PRIORITY scheduling. (c)    Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling. (d)     Draw a...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs.       Draw a Gantt chart showing preemptive PRIORITY scheduling. Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling.     Draw a...
Consider the following set of jobs to be scheduled for execution on a single CPU system....
Consider the following set of jobs to be scheduled for execution on a single CPU system. Job Arrival Time Burst (msec) Priority A 0 6 3 (Silver) B 1 2 1 (Diamond) C 3 5 3 (Silver) D 5 3 4 (Bronze) E 7 2 2 (Gold)    (a)     Draw a Gantt chart showing First-Come-First-Served (FCFS) scheduling for these jobs. (b)     Draw a Gantt chart showing preemptive PRIORITY scheduling. (c)    Draw a Gantt chart showing Highest Response Ratio Next (HRRN) scheduling. (d)     Draw a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT