1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
In-s [12.5K]
3 years ago
6

Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num i

s an integer variable that has been initialized, and that there are functions f1, f2, f3, and f4. Do not use any if or if-else statements in the actions in the switch statement, only calls to the four functions.
Engineering
1 answer:
seropon [69]3 years ago
8 0

Answer:

Answer explained below

Explanation:

The following is the nested if-else statement:

% if-based statement

if num < -2 ||  num > 4

          f1(num)

else

     if num <=2

          if num >= 0

              f2(num)

          else

              f3(num)

          end

     else

          f4(num)

     end

end

<u>NOTE:</u> the num is an integer variable that has been initialized and that there are functions f1, f2, f3 and f4.

   

The nested if-else statement can be replaced by switch statement as shown below:

switch num

    case(0, 1, 2)

         f2(num)

    case(-2, -1)

         f3(num)

    case(3, 4)

         f4(num)

    otherwise

         f1(num)

In this case, the switch based code is easier to write and understand because the cases are single valued or a few discrete values (not ranges of values)

You might be interested in
Do heavier cars really use more gasoline? Suppose a car is chosen at random. Let x be the weight of the car (in hundreds of poun
Alex17521 [72]

Answer:

Answer is explained in the explanation section below.

Explanation:

Solution:

Note: This question is incomplete and lacks necessary data to solve. But I have found the similar question on the internet. So, I will be using the data from that question to solve this question for the sack of concept and understanding.

Data Given:

x = 27 , 44 , 32 , 47, 23 , 40, 34, 52

y = 30, 19,  24,  13 , 29,  19,  21,  14

It is given that,

∑x = 299

∑y = 167

∑x^{2} = 11887

∑y^{2} = 3773

We are asked to verify the above values manually in this question.

So,

1. ∑x = 299

Let's verify it:

∑x = 27 + 44 + 32 + 47 + 23 + 40 + 34 + 52

∑x = 299

Yes, it is equal to the given value. Hence, verified.

2. ∑y = 167

Let's verify it:

∑y = 30 + 19 +  24 + 13 + 29 + 19 +  21 +  14

∑y = 169

No, it is not equal to the given value.

3. ∑x^{2} = 11887

Let's verify it:

For this to find,  first we need to square all the value of x individually and then add them together to verify.

∑x^{2} = 27^{2} + 44^{2} + 32^{2} + 47^{2} + 23^{2} + 40^{2} + 34^{2} + 52^{2}

∑x^{2} = 11,887

Yes, it is equal to the given value. Hence, verified.

4. ∑y^{2} = 3773

Let's verify it:

Again, for this we need to find the squares of all the y values and then add them together to verify it.

∑y^{2} = 30^{2} + 19^{2} +  24^{2} + 13^{2} + 29^{2} + 19^{2} +  21^{2} +  14^{2}

∑y^{2}  = 3,845

No, it is not equal to the given value.

4 0
3 years ago
A car has a steering wheel with a 15 inch diameter that takes 18 lbs of Effort force to move is
elena-14-01-66 [18.8K]

Answer: A first class lever in static equilibrium has a 50lb resistance force and 15lb effort force. The lever's effort force is located 4 ft from the fulcrum.

Explanation:

4 0
3 years ago
Q1: The first option should always be to get out safely (RUN)
nekit [7.7K]

Answer:

Q1 true

Q2 true

And other I am confuse

6 0
3 years ago
Find the rate of heat transfer through a 6 mm thick glass window with a cross-sectional area of 0.8 m2 if the inside temperature
kiruha [24]

Answer:

6.9

Explanation:

I had the same question lol your welcomr if itd not right in sorry

3 0
3 years ago
Which of the eight diagnostic steps for locating an engine performance problem is performed first?
Kay [80]

Answer:

D. Perform a thorough visual inspection.

4 0
3 years ago
Other questions:
  • Pick a subjectarea/field/topic that you are interested in. For each of the following Bonham- Carver uses of GIS give an example
    7·1 answer
  • What is an ip<br> Number
    12·1 answer
  • What is electromagnetic induction?
    14·1 answer
  • Unwanted resistance is being discussed.
    12·1 answer
  • 2 Consider airflow over a plate surface maintained at a temperature of 220°C. The temperature profile of the airflow is given as
    13·1 answer
  • #198. Moment of inertia about center of a segmented bar A bar of width is formed of three uniform segments with lengths and area
    7·1 answer
  • In water and wastewater treatment processes a filtration device may be used to remove water from the sludge formed by a precipit
    10·1 answer
  • Cold forging makes metal more workable than hot forging.<br> True<br> False
    11·2 answers
  • ⚠️I mark BRIANLIST ⚠️The same engineering teams are able to design and develop the different subsystems for an airplane.
    5·2 answers
  • A furnace uses preheated air to improve its fuel efficiency. Determine the adiabatic flame temperature when the furnance is oper
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!