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
Pin supports, such as that at A, may have horizontal and vertical components to the support reaction. Roller supports, such as t
aliya0001 [1]

Answer:

hello your question is incomplete below is the missing part of the question and attached is the missing diagram

In the simply-supported beam shown in the figure below, d1=14 ft, d2=7 ft, and F=15 kips. so find Az, Ay, By.(in kips)

answer :

Reaction force at B = 10 kips

Reaction force in the y axis = 5 kips

Reaction force in the Z direction = 0 kips

Explanation:

Taking moment about point A

∑ Ma = 0

By + ( d1 + d2 ) - F*d1 = 0

By ( reaction force at B ) = ( 15 * 14 ) / ( 21 ) =  10 kips

Applying equilibrium  forces in the Y-axis

∑ Fy = 0

Ay - F + By = 0

where : F = 15, By = 10

hence ; Ay = 5 kips

applying equilibrium forces in the Z-direction

∑ Fz = 0

Az = 0 kips

6 0
3 years ago
Jack has been concerned about the rapidly changing green regulations in his state and his ability as a mechanical engineer to ke
uysha [10]

Answer:

Option A, B and D

Explanation:

Jack can easily convince boss if he focus around two major aspects of the company

a) Revenue enhancement - Jack must outline the benefits of his research that can be used to improvise customer offerings and  hence can be further used to devise more energy-efficient options to customer

b) Reduction in mistakes - Issues such as poor implementation can be avoided with better approach and understanding.

Hence, option A, B and D are correct

3 0
3 years ago
How is a Doctor Who is a generalist different a specialist?
bekas [8.4K]

Answer:

specialist focus in one very specific thing, generalist focus and many things, they are like a jack of all trades

7 0
3 years ago
What are the relative volume requirements for a CM reactor compared to a PF reactor if first-order kinetics apply and treatment
Tanzania [10]

Answer:

look it up

Explanation:

6 0
3 years ago
Write in an Excel cell the appropriate @RISK function for a binomial distribution that results from 50 trials with probability o
borishaifa [10]

Answer:

Binomial Function

I got my output using the formula = 1 - BINOMDIST (17, 50, 0.3, TRUE)

Then got the cumulative probability distribution at 17 to be 0.2178

Explanation:

To draw a normal distribution:

1. Got to '@risk' and click on 'defined distribution'

2. Select 'binomial' in function block

3. enter formula in cell formula and click okay

The use of @RISK to draw a binomial distribution of 50 trials and probability of success as 0.3 by entering formular =RISKBINOMIAL (50, 0.3).

6 0
3 years ago
Other questions:
  • Assume that the flow of air through a given duct is isentropic. At one point in the duct, the pressure and temperature are pl =
    15·1 answer
  • A refrigerator removes heat from a refrigerated space at 0°C at a rate of 2.2 kJ/s and rejects it to an environment at 20°C. wha
    15·1 answer
  • Consider the following Moore’s law growth pattern (since 1980) for the number of transistors inside a particular commercial micr
    12·1 answer
  • If gain of the critically damped system is increased, the system will behave as a) Under damped b) Over damped c) Critically dam
    13·1 answer
  • Two sections of a pressure vessel are to be held together by 5/8 in-11 UNC grade 5 bolts. You are told that the length of the bo
    11·1 answer
  • Consider the base plate of an 800-W household iron with a thickness of L 5 0.6 cm, base area of A 5 160 cm2, and thermal conduct
    15·1 answer
  • Witch part of the testing and evaluation stage of designing a PDA
    9·1 answer
  • Forcing a solid piece of heated aluminum through a die forms:
    15·2 answers
  • How long did it take the Niagara power plant to be built
    14·2 answers
  • Please help me. I have no idea what I'm doing.​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!