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
m_a_m_a [10]
3 years ago
7

Use the case structure in order to do the following tasks. a) Use a five layer case structure in order to do following for a two

numbers entered by the user. i.Addition of two numbers. ii.Subtraction of two numbers. iii.Multiplication of two numbers. iv.Division of two numbers (check for the user input such that dominator ≠0).r v. Negate the two numbers.b) Use the case a structure to find the square root for a real number > 0. The code will accept the number from the user and check if it is > 0 to calculate the square root, otherwise it gives an error.

Engineering
1 answer:
Igoryamba3 years ago
8 0

Answer:

The complete answer along with step by step explanation and output results is provided below.

Explanation:

Task a)

#include<iostream>

using namespace std;

int main()

{

  int op;

  double num1, num2;

   cout<<"Enter num1 and num2"<<endl;

   cin>>num1>>num2;  

  // To provide the option of required 5 cases  

  cout << "Select the operation:"

          "\n1 = Addition"

          "\n2 = Subtraction"

          "\n3 = Multiplication"

          "\n4 = Division"

          "\n5 = Negation\n";

  cin >> op;  // user input the desired operation

  switch(op)  // switch to the corresponding case according to user input

   {

       case 1:

           cout <<"The Addition of num1="<<num1<<" and num2="<<num2<<" is: "<<num1+num2;

           break;

       case 2:

           cout <<"The Subtraction of num1="<<num1<<" and num2="<<num2<<" is: "<<num1-num2;

           break;

       case 3:

           cout <<"The Multiplication of num1="<<num1<<" and num2="<<num2<<" is: "<<num1*num2;

           break;

       case 4:        

        while(num2 == 0) // to check if divisor is zero  

        {

           cout << "\nWrong divisor! Please select the correct divisor again: ";

           cin >> num2; // if divisor is zero then ask user to input num2 again

        }

           cout <<"The division of num1="<<num1<<" and num2="<<num2<<" is: "<<num1/num2;

           break;

       case 5:

           cout <<"The Negation of num1="<<num1<<" and num2="<<num2<<" is: "<<-1*num1<<" "<<-1*num2;

           break;

       default:

           // If the operation is other than listed above then error will be shown

           cout << "Error! The selected operatorion is not correct";

           break;

   }

  return 0;

}

Output:

Test 1:

Enter num1 and num2

2

9

Select the operation:

1 = Addition

2 = Subtraction

3 = Multiplication

4 = Division

5 = Negation

1

The Addition of num1=2 and num2=9 is: 11

Hence the output is correct and working as it was required

Test 2:

Enter num1 and num2

8

0

Select the operation:

1 = Addition

2 = Subtraction

3 = Multiplication

4 = Division

5 = Negation

4

Wrong divisor! Please select the correct divisor again: 2

The Division of num1=8 and num2=2 is: 4

Hence the output is correct and working as it was required

Test 3:

Enter num1 and num2

-2

4

Select the operation:

1 = Addition

2 = Subtraction

3 = Multiplication

4 = Division

5 = Negation

5

The Negation of num1=-2 and num2=4 is: 2 -4

Hence the output is correct and working as it was required

Task b)

#include<iostream>

#include<cmath>   // required to calculate square root

using namespace std;

int main()

{

  int op;

  double num;

   cout<<"Enter a real number > 0"<<endl;

   cin>>num;

  cout << "Press 1 for square root:";

  cin >> op;

  switch(op)  // switch to the corresponding case according to user input

   {

       case 1:

          if (num <= 0) // to check if number is less or equal to zero

        {

           cout << "\nError! number is not valid";

           break;   // if number is not valid then terminate program

        }

           cout <<"The square root of num="<<num<<" is: "<<sqrt(num);

// if number is valid then square root will be calculated

           break;

       default:

           // If the operation is other than listed above then error will be shown

           cout << "Error! The selected operation is not correct";

           break;

   }

  return 0;

}

Output:

Test 1:

Enter a real number > 0

6

Press 1 for square root: 1

The square root of num=6 is: 2.44949

Hence the output is correct and working as it was required

Test 2:

Enter a real number > 0

-4

Press 1 for square root: 1

Error! number is not valid

Hence the output is correct and working as it was required

You might be interested in
How many power station do we have​
loris [4]

Answer: 9,719

Explanation:

5 0
3 years ago
Consider two different versions of algorithm for finding gcd of two numbers (as given below), Estimate how many times faster it
juin [17]

Answer:

Explanation:

Step 1:

a) The formula for compute greatest advisor is

     gcd(m,n) = gcd (n,m mod n)

the gcd(31415,14142) by applying Euclid's algorithm is

    gcd(31,415,14,142) =gcd(14,142,3,131)

                                  =gcd=(3,131, 1,618)

                                   =gcd(1,618, 1,513)

                                   =gcd(1,513, 105)

                                   =gcd(105, 43)

                                    =gcd(43, 19)

                                     =gcd(19, 5)

                                      =gcd(5, 4)

                                      =gcd(4, 1)

                                      =gcd(1, 0)

                                      =1

STEP 2

b)  The number of comparison of given input with the algorithm based on  checking consecutive integers and Euclid's algorithm is

     The number of division using Euclid's algorithm =10 from part (a)

      The consecutive integer checking algorithm:

      The number of iterations =14,142 and 1 or 2 division of iteration.

        14,142 ∠= number of division∠ = 2*14,142

         Euclid's algorithm is faster by at least 14,142/10 =1400 times

          At most 2*14,142/10 =2800 times.

5 0
3 years ago
Question text
lisabon 2012 [21]

Answer:

That's a really nice question sadly I don't know the answer I'm replying to you cuz I'm tryna get points so... Sorry

3 0
4 years ago
A long, circular aluminum rod is attached at one end to a heated wall and transfers heat by convection to a cold fluid.
Trava [24]

Answer:

a. Heat removal rate will increase

b. Heat removal rate will decrease

Explanation:

Given that

One end of rod is connected to the furnace and rod is long.So this rod can be treated as infinite long fin.

We know that heat transfer in fin given as follows

Q_{fin}=\sqrt{hPKA}\ \Delta T

We know that area

A=\dfrac{\pi}{4}d^2

Now when diameter will triples then :

A_f=\dfrac{\pi}{4}{\left (3d \right )}^2

A_f=9A

Q'_{fin}=\sqrt{9hPKA}\ \Delta T

Q'_{fin}=3\sqrt{hPKA}\ \Delta T

Q'_{fin}=3Q

So the new heat transfer will increase by 3 times.

Now when copper rod will replace by aluminium rod :

As we know that thermal conductivity(K) of Aluminium is low as compare to Copper .It means that heat transfer will decreases.

3 0
3 years ago
Increase vehicle control through lane position and speed adjustments is not necessary risk management, just common sense.
Vesnalui [34]
True

If it was wrong I’m sorry
6 0
3 years ago
Other questions:
  • An 80-L vessel contains 4 kg of refrigerant-134a at a pressure of 160kPa. Determine (a) the temperature, (b) the quality, (c) th
    11·1 answer
  • . Consider the single-engine light plane described in Prob. 2. If the specific fuel consumption is 0.42 lb of fuel per horsepowe
    9·1 answer
  • g In the above water treatment facility, chemical concentration (mg/gal) within the tank can be considered uniform. The initial
    8·1 answer
  • A evolução da malha rodoviária do Brasil é um marco notável
    9·1 answer
  • I need solution for this question please ​
    7·2 answers
  • Heat in the amount of 100 kJ is transferred directly from a hot reservoir at 1200 K to a cold reservoir at 600 K. Calculate the
    15·1 answer
  • The water in an 8-m-diameter, 3-m-high above-ground swimming pool is to be emptied by unplugging a 3-cm-diameter, 25-m-long hori
    9·1 answer
  • A cylindrical specimen of a titanium alloy having an elastic modulus of 107 GPa (15.5 × 106 psi) and an original diameter of 3.7
    14·1 answer
  • Cite another example of information technology companies pushing the boundaries of privacy issues; apologizing, and then pushing
    9·1 answer
  • सत्य से अधिक उपयोगी एवं आज्ञापालन से श्रेष्ठ क्या है ?<br>answer fast plz​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!