Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 4 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 27 Jul 2017 My Price 14.00

mathematical operation

In C++, write a program that allows the user to select a mathematical operation to solve. Each operation will be

implemented as a function; a single "helper" function will gather the operands needed for the selected

operation. Some of these operations can "break" under certain conditions (e.g. divide by 0), so the functions

must be able to flag any errors by returning an error code (we provide global constants for these codes).

Develop this program one function at a time, starting with the "helper" function for operand input; for

each function, write a "test harness" that tests it for a variety of inputs.

Global constants and function prototypes

const int OK = 0;

const int DIV_ZERO = 1;

const int SQRT_ERR = 2;

int acquireOperands(const string &op, double& x, double &y, double &z);

int division(double a, double b, double& result);

int quadratic(double a, double b, double c, double& root1, double &root2);

int pythagorean(double a, double b, double& c);

The functions

1. acquireOperands: 1 const string reference parameter (requested operation),

3 double reference parameters (for up to 3 operands);

returns number of user inputs acquired by this function, e.g. the "division" operation has 2 inputs and

thus the function would return the value 2.

2. division: calculates a/b

2 value parameters (for operands), 1 reference parameter (for result);

returns error constant meaning "Divide by 0" or the constant for "OK"

3. Pythagorean equation: hypotenuse c = sqrt(a2

2 value parameters (for operands), 1 reference parameter (for result);

returns error constant for "OK" (no possible errors)

4. quadratic equation: solves ax2

+ b2

)

+ bx + c = 0

3 value parameters (for operands), 2 reference parameters (for two roots);

returns error code meaning "OK", or "Divide by 0", or "Negative Discriminant"

Notes:

the operation is acquired in main and then provided to acquireOperands

acquireOperands must request ONLY the number of inputs required for the operation

the operation functions do NOT "return" their results to main: results are communicated via the

reference parameters. The return value is used for the error codes/constants.

there is NO input or output in any of the operation functions - all i/o is in main or acquireOperands

you will need to include the cmath library

main function

Once you have your functions written and tested, you can write main:

Prompt the user to select an operation.

If the choice is anything other than "division" or "pythagorean" or "quadratic", output a

message "Operation not supported", and continue to prompt until a proper choice is made.

Once you have a valid operation, invoke acquireOperands to acquire the correct number of operands

for the operation (you will capture this number into a variable in main, but you won't actually use that

variable for anything in this assignment).

now you can invoke the appropriate operation function, and display the requested operation

(Equation: ), and either the result(s) (Result: ) or the appropriate error message (Error: ), as

per the examples. Potential errors:

Operation not supported.

Cannot divide by zero.

Cannot take square root of a negative number.

 

Example Runs:

Please choose an operation: quadratic

Enter your first number: 1

Enter your second number: 0

Enter your third number: -4.84

Equation: 1x^2 + 0x + -4.84 = 0

Result: -2.2, 2.2

 

Please choose an operation: division

Enter your first number: 1.5

Enter your second number: 0

Equation: 1.5 / 0

Error: Cannot divide by zero.

 

Please choose an operation: Gobble

Error: Operation not supported.

Please choose an operation: Add

Error: Operation not supported.

Please choose an operation: division

Enter your first number: 2

Enter your second number: 3

 

Please choose an operation: quadratic

Enter your first number: 1

Enter your second number: -8

Enter your third number: 16

Equation: 1x^2 + -8x + 16 = 0

Result: 4

Answers

(5)
Status NEW Posted 27 Jul 2017 09:07 AM My Price 14.00

Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â-----------  -----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------acq-----------uis-----------iti-----------on -----------of -----------my -----------sol-----------uti-----------on.-----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- ca-----------tch-----------

Not Rated(0)