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
Locate the centroid y¯ of the composite area. Express your answer to three significant figures and include the appropriate units
german

Answer:

Please see the attached Picture for the complete answer.

Explanation:

4 0
3 years ago
Marcus wants to pursue a career in civil engineering. He aims to work for the city council as a civil engineer. What examination
Rzqust [24]

Answer:

Marcus would have to take an exam administered by the national council of examiners for engineering and surveying.

Explanation:

Civil engineers design, construct, and maintain projects regarding infrastructure. A civil engineer also looks after the systems in the public and private sectors like roads, buildings, and systems for water supply and sewage treatment.

In order to pursue a career in civil engineering, Marcus aims to work for the city council as a civil engineer. Therefore, he would have to take an exam administered by the national council of examiners for engineering and surveying.

6 0
3 years ago
What is one advantage corporations have over other types of businesses
SpyIntel [72]
Liability, easy transferring of owner ships
4 0
3 years ago
Design a circuit that outputs a 1 when the bit pattern (101) has been applied to input, and 0 otherwise.
just olya [345]

Answer:

  see the attachment

Explanation:

The circuit shown uses Nand and Nor gates to produce the desired logic. The input bits are numbered 0 to 2, right to left.

The logic is ...

  out = ((b2·b0)' + b1)'

  out = b2·b1'·b0

4 0
3 years ago
A blown shaft seal on a hydraulic motor is usually the result of
torisob [31]
It is High system pressure
8 0
3 years ago
Read 2 more answers
Other questions:
  • Two kg of N2 at 450 K, 7 bar is contained in a rigid tank connected by a valve to another rigid tank holding 1 kg of O2 at 300 K
    13·1 answer
  • Thermoplastics burn upon heating. a)-True b)- false?
    14·1 answer
  • What’s a pigtail when wiring
    7·1 answer
  • Assume that in orthogonal cutting the rake angle is 15° and the coefficient of friction is 0.15. a. Determine the percentage cha
    14·1 answer
  • Believing that 70% of her body is composed of water, and 20% is composed of denser materials (bones, teeth, etc.) with a specifi
    5·1 answer
  • What are the benefits of using a multi view sketch to communicate a design
    14·1 answer
  • Tech A says that multiple gasket or seal leaks can be caused by a defective exhaust gas recirculation (EGR) system.
    5·1 answer
  • An automotive fuel cell consumes fuel at a rate of 28m3/h and delivers 80kW of power to the wheels. If the hydrogen fuel has a h
    15·1 answer
  • The Environmental Protection Agency is likely to consider the effect of building activity on what aspect of water? (Select all t
    9·1 answer
  • Schrodinger equation is a ........... Equation
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!