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
If a law enforcement officer stops a vehicle for a traffic violation and finds a front-seat passenger 18 years of age or older n
Serggg [28]

Safety belt violation would be charged to the front seat passenger.

Answer: Option A.

<u>Explanation:</u>

Essential safety belt laws permit law implementation officials to ticket a driver or traveler for not wearing a safety belt, with no other traffic offense occurring. 11 states incorporate back seats as auxiliary implementation. Five of these are states with essential safety belt laws for front seat tenants.

In 15 of the 50 expresses, the safety belt law is viewed as an optional offense, which implies that a cop can't stop and ticket a driver for the sole offense of not wearing a safety belt. (One special case to this is Colorado, where kids not appropriately limited is an essential offense and brings an a lot bigger fine.)

6 0
3 years ago
In a semiconductor manufacturing process, three wafers from a lot are tested. Each wafer is classified as pass or fail. Assume t
gladu [14]

Answer:

F(x) = 0           ;  x < 0

         0.064   ;  0 ≤ x < 1

         0.352   ;  1 ≤ x < 2

         0.784   ;  2 ≤ x < 3

            1        ;    x ≥ 3

Explanation:

Each wafer is classified as pass or fail.

The wafers are independent.

Then, we can modelate X : ''Number of wafers that pass the test'' as a Binomial random variable.

X ~ Bi(n,p)

Where n = 3 and p = 0.6 is the success probability

The probatility function is given by :

P(X=x)=f(x)=nCx.p^{x}.(1-p)^{n-x}

Where nCx is the combinatorial number

nCx=\frac{n!}{x!(n-x)!}

Let's calculate f(x) :

f(0)=3C0.(0.6^{0}).(0.4^{3})=0.4^{3}=0.064

f(1)=3C1.(0.6^{1}).(0.4^{2})=0.288

f(2)=3C2.(0.6^{2}).(0.4^{1})=0.432

f(3)=3C3.(0.6^{3}).(0.4^{0})=0.6^{3}=0.216

For the cumulative distribution function that we are looking for :

P(X\leq x)=F(x)

F(0)=f(0)\\F(1)=f(0)+f(1)\\F(2)=f(0)+f(1)+f(2)\\F(3)=f(0)+f(1)+f(2)+f(3)=1

F(0)=0.064\\F(1)=0.064+0.288=0.352\\F(2)=0.064+0.288+0.432=0.784\\F(3)=0.064+0.288+0.432+0.216=1

The cumulative distribution function for X is :

F(x) = 0           ;  x < 0

         0.064   ;  0 ≤ x < 1

         0.352   ;  1 ≤ x < 2

         0.784   ;  2 ≤ x < 3

            1        ;    x ≥ 3

5 0
3 years ago
(20 points) (Assessment of Outcome 1): A plant has two identical standby generator units for emergency use. In the area of the g
erastovalidia [21]

Answer:

It wouldn't get any louder then maybe 3db more

Explanation:

There's even a equation if you wanted to check this out but, if they are the same generator same model and all and made the same precise noise it wouldn't increase more then 3db.

5 0
4 years ago
If a master cylinder piston applies pressure to a brak piston that has twice as much square area what will be the force from the
sp2606 [1]

Explanation:

Pressure = force/area

Pressure stays the same.

If the area is doubled the force is doubled.

5 0
4 years ago
Two Technicians are discussing the Battery Council
nexus9112 [7]

Answer:

Technician A

Explanation:

The Battery Council  International (BCI) battery group numbers is an industry standard for batteries that indicate two important this;

  1. Physical size of a car battery which are; height , width and length.
  2. Polarity on the battery which is the location of the positive and negative battery posts

For example : a group 24 battery or a type 27 marine battery are battery group numbers that define the physical dimensions of a battery case. These numbers are important because car owners and manufacturers use the numbers <em>to match vehicle power requirements with the alternators </em>.A mismatch of the battery and the alternator can cause the vehicle's alternator to overheat leading to a short life span.

<u>Technician A statement is correct.</u>

3 0
3 years ago
Other questions:
  • 4. A 25 km2 watershed has a time of concentration of 1.6 hr. Calculate the NRCS triangular UH for a 10-minute rainfall event and
    8·1 answer
  • An incoming signal is at a frequency of 500kHz. This signal needs to be acquired and all other signals attenuated. Design a pass
    5·1 answer
  • Which option is a potential environmental benefit of adopting a new<br> technology?
    9·2 answers
  • Describe the "Bauschinger Effect" on the stress strain behaviour of steel
    15·1 answer
  • Explain the process of predicting equipment failure?
    12·1 answer
  • How does a turbo charger work
    12·2 answers
  • For Figure Below, if the elevation of the benchmark A is 25.00 m above MSL:
    14·1 answer
  • Pleaseeee help me with this!!
    10·1 answer
  • Which statement explains what causes the balloon to accelerate
    14·1 answer
  • What is explanation of powered air purifiying respirators
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!