answer.
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]
2 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]2 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
At his review last year, Lucas was promised a 20 percent raise if he met his production goals. Raises were included in today’s p
Murrr4er [49]

Answer: Instrumentality;low

Explanation: Instrumentality is the impact a person have or will be able to render to a given activity or his or her job. The Instrumentality of a person has been found to be proportional to the what outcome of the person's efforts. Especially if the person's explanations are meant.

When a person's expectations are not meant it will cause the person's Instrumentality to be low.

4 0
2 years ago
Dust, dirt, or metal chips can pose a potential ____ injury risk in a shop.
pantera1 [17]

Answer:

Eye.

Explanation:

Dust, dirt, and metal chips are most unpleasant to get in your eyes. Just experience it and you'll know what I mean.

;)

3 0
2 years ago
Consider film condensation on a vertical plate. Will the heat flux be higher at the top or at the bottom of the plate? Why?
STALIN [3.7K]

Answer:

During film condensation on a vertical plate, heat flux at the top will be higher since the thickness of the film at the top, and thus its thermal resistance, is lower.

Explanation:

https://www.docsity.com/pt/cengel-solution-heat-and-mass-transfer-2th-ed-heat-chap10-034/4868218/

https://arc.aiaa.org/doi/pdf/10.2514/1.43136

https://arxiv.org/ftp/arxiv/papers/1402/1402.5018.pdf

8 0
2 years ago
The wires each have a diameter of 12 mm, length of 0.6 m, and are made from 304 stainless steel. Determine the magnitude of forc
Sonbull [250]

Answer:

Magnitude of force P = 25715.1517 N

Explanation:

Given - The wires each have a diameter of 12 mm, length of 0.6 m, and are made from 304 stainless steel.

To find - Determine the magnitude of force P so that the rigid beam tilts 0.015∘.

Proof -

Given that,

Diameter = 12 mm = 0.012 m

Length = 0.6 m

\theta = 0.015°

Youngs modulus of elasticity of 34 stainless steel is 193 GPa

Now,

By applying the conditions of equilibrium, we have

∑fₓ = 0, ∑f_{y} = 0, ∑M = 0

If ∑M_{A} = 0

⇒F_{BC}×0.9 - P × 0.6 = 0

⇒F_{BC}×3 - P × 2 = 0

⇒F_{BC} = \frac{2P}{3}

If ∑M_{B} = 0

⇒F_{AD}×0.9 = P × 0.3

⇒F_{AD} ×3 = P

⇒F_{AD} = \frac{P}{3}

Now,

Area, A = \frac{\pi }{4} X (0.012)^{2} = 1.3097 × 10⁻⁴ m²

We know that,

Change in Length , \delta = \frac{P l}{A E}

Now,

\delta_{AD} = \frac{P(0.6)}{3(1.3097)(10^{-4}) (193)(10^{9}  } = 9.1626 × 10⁻⁹ P

\delta_{BC} = \frac{2P(0.6)}{3(1.3097)(10^{-4}) (193)(10^{9}  } = 1.83253 × 10⁻⁸ P

Given that,

\theta = 0.015°

⇒\theta = 2.618 × 10⁻⁴ rad

So,

\theta =  \frac{\delta_{BC} - \delta_{AD}}{0.9}

⇒2.618 × 10⁻⁴ = (  1.83253 × 10⁻⁸ P - 9.1626 × 10⁻⁹ P) / 0.9

⇒P = 25715.1517 N

∴ we get

Magnitude of force P = 25715.1517 N

6 0
2 years ago
1. Consider the steady flow in a water pipe joint shown in the diagram. The areas are:
marshall27 [118]

Answer:

-4.5 m/s

Explanation:

Assuming steady and incompressible flow and uniform properties at each section

V_1A_1+V_2A_2+A_3V_3+Q_4=0

Here V is velocity of flow and A is area, Q is flow rate out of the leak, subscript 1-4 represent different sections

At the surface,  is negative hence the equation above will be

-V_1A_1+V_2A_2+A_3V_3+Q_4=0

Making  the subject of the formula then

V_2=\frac {V_1A_1-A_3V_3-Q_4}{A_2}

Substituting the given values then

V_2=\frac {(5\times 0.2)-(12\times 0.15)-0.1}{0.2}=-4.5 m/s\\V_2=-4.5m/s

8 0
2 years ago
Other questions:
  • A binary star system consists of two stars of masses m1m1m_1 and m2m2m_2. The stars, which gravitationally attract each other, r
    9·1 answer
  • Show that a chirped Gaussian pulse is compressed initially inside a single-mode fiber when ftC &lt; 0. Derive expressions for th
    12·1 answer
  • 4.9 Given that I 4 amps when Vs 40 volts and Is 4 amps and I 1 amp when Vs 20 volts and Is 0, use superposition and linearity to
    5·1 answer
  • The driving force for fluid flow is the pressure difference, and a pump operates by raising the pressure of a fluid (by converti
    13·1 answer
  • Define initial set and final set. Briefly discuss one method used to determine them. The following laboratory tests are performe
    12·1 answer
  • A sample of normally consolidated clay was subjected to a CU triaxial compression test that was carried out until the specimen f
    6·1 answer
  • A certain printer requires that all of the following conditions be satisfied before it will send a HIGH to la microprocessor ack
    12·1 answer
  • Water at 70 kPa and 1008C is compressed isentropically in a closed system to 4 MPa. Determine the final temperature of the water
    6·1 answer
  • Air ows steadily in a thermally insulated pipe with a constant diameter of 6.35 cm, and an average friction factor of 0.005. At
    5·1 answer
  • How does Accenture generate value for clients through Agile and DevOps?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!