Alpha Geek

(8)

$10/per page/Negotiable

About Alpha Geek

Levels Tought:
University

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Environmental science,Essay writing,Programming,Social Science,Statistics Hide all
Teaching Since: Apr 2017
Last Sign in: 438 Weeks Ago, 2 Days Ago
Questions Answered: 9562
Tutorials Posted: 9559

Education

  • bachelor in business administration
    Polytechnic State University Sanluis
    Jan-2006 - Nov-2010

  • CPA
    Polytechnic State University
    Jan-2012 - Nov-2016

Experience

  • Professor
    Harvard Square Academy (HS2)
    Mar-2012 - Present

Category > Programming Posted 29 May 2017 My Price 10.00

In C++, write a program that allows the user to select a 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

(8)
Status NEW Posted 29 May 2017 07:05 AM My Price 10.00

-----------

Attachments

1496042729-2192676_2_636315555273914079_sample-output.PNG
file 1496042756-Answer.docx preview (1350 words )
#-----------inc-----------lud-----------e &-----------amp-----------;lt-----------;io-----------str-----------eam-----------&am-----------p;g-----------t; ----------- #i-----------ncl-----------ude----------- &a-----------mp;-----------lt;-----------str-----------ing-----------&am-----------p;g-----------t; ----------- #i-----------ncl-----------ude----------- &a-----------mp;-----------lt;-----------cma-----------th&-----------amp-----------;gt-----------; -----------usi-----------ng -----------nam-----------esp-----------ace----------- st-----------d; ----------- co-----------nst----------- in-----------t O-----------K =----------- 0;----------- c-----------ons-----------t i-----------nt -----------DIV-----------_ZE-----------RO -----------= 1-----------; -----------con-----------st -----------int----------- SQ-----------RT_-----------ERR----------- = -----------2; ----------- in-----------t a-----------cqu-----------ire-----------Ope-----------ran-----------ds(-----------con-----------st -----------str-----------ing----------- &a-----------mp;-----------amp-----------;op-----------, d-----------oub-----------le -----------&am-----------p;a-----------mp;-----------x, -----------dou-----------ble----------- &a-----------mp;-----------amp-----------;y,----------- do-----------ubl-----------e &-----------amp-----------;am-----------p;z-----------); ----------- in-----------t d-----------ivi-----------sio-----------n(d-----------oub-----------le -----------a, -----------dou-----------ble----------- b,----------- do-----------ubl-----------e &-----------amp-----------;am-----------p;r-----------esu-----------lt)-----------; -----------int----------- qu-----------adr-----------ati-----------c(d-----------oub-----------le -----------a, -----------dou-----------ble----------- b,----------- do-----------ubl-----------e c-----------, d-----------oub-----------le -----------&am-----------p;a-----------mp;-----------roo-----------t1,----------- do-----------ubl-----------e &-----------amp-----------;am-----------p;r-----------oot-----------2);-----------
Not Rated(0)