Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: DO NOT move on to this part of the assignment until Part 1 runs correctly. For part 2 of the assignment, code functions

Part 2:

DO NOT move on to this part of the assignment until Part 1 runs correctly.

For part 2 of the assignment, code functions that will perform the various arithmetic operations and then call the functions in main(). The calling statements that are placed in main() should replace the calculations that are currently in the switch statement.

The Functions

Write and use the following 7 functions in the program.

int addition( int value1, int value2 )

This function will calculate and return the sum of two numbers. It takes two arguments: the two integer values to add together. It returns an integer: the sum of the two integer values. The function should simply calculate the sum of the two values and return the result.

int subtraction( int value1, int value2 )

This function will calculate and return the difference of two numbers. It takes two arguments: the two integer values to be subtracted. It returns an integer: the difference of the two integer values. The function should simply subtract the second value from the first value and return the result.

int multiplication( int value1, int value2 )

This function will calculate and return the product of two numbers. It takes two arguments: the two integer values to be multiplied together. It returns an integer: the product of the two integer values. The function should simply calculate the product of the two values and return the result.

int quotient( int value1, int value2 )

This function will calculate and return the quotient that results when dividing two integer values. It takes two arguments: the two integer values to be divided. It returns an integer: the quotient. The function should simply divide the first value by the second value to calculate the quotient and return the result.

int remainder( int value1, int value2 )

This function will calculate and return the remainder that results when dividing two integer values. It takes two arguments: the two integer values to be divided. It returns an integer: the quotient. The function should simply divide the first value by the second value to calculate the remainder and return the result.

int power( int base, int powerValue )

This function will calculate the product of raising a number to a power. It takes two arguments: the two integer values to be used in the calculation. It returns an integer: the product of raising a number to a power. The function should use a loop to calculate the product of raising the first value (the base) to a power (the second value) and return the result.

Note: remember that if the power (the second value) is 0, the result is 1.

DO NOT use the pow function that is part of the cmath library. You're writing your own version of that function.

int factorial( int value )

This function will calculate the factorial of an integer value. It takes one argument: the integer value that is used in the factorial calculation. It returns an integer: the factorial of the value. The function should use a loop to calculate the factorial of the integer value and return the result.

The factorial of a value is the product of 1 times all of the values through the integer value. So the factorial of 4 is the product of 1 * 2 * 3 * 4. The exception is the factorial of 0 which is equal to 1.

Part 2 Requirement

Each function must have a documentation box explaining:

/*************************************************************** Function: Use: Arguments: Returns: Note: ***************************************************************/ 

See the documentation standards on the course webpage for more examples or if further clarification is needed. Your program will not get full credit (even if it works correctly) if these standards are not followed

As with the previous assignment and the assignments until the end of the semester, complete program documentation is required. For this assignment, that means that line documentation AND function documentation boxes are needed. In regards to line documentation, there is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describe what the "chunk" of code does. Make sure that main() and any function that you write contains line documentation

its name

its use or function: that is, what does it do? What service does it provide to the code that calls it?

a list of its arguments briefly describing the meaning and use of each

the value returned (if any) or none

notes on any unusual features, assumptions, techniques, etc.

Part 2 Output

The output for part 2 is exactly the same as part 1.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Partial Program to part 1

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include #include

using namespace std;

int fact(int number)

{

int fact=1;

for (int i = 1; i <= number; i++)

fact*=i;

return fact;

}

int main(){

char operation;

cout << "What operation would you like to perform: " << endl;

while(1){

cout<< " + addition" << endl

<< " - subtraction" << endl

<< " * multiplication" << endl

<< " / division" << endl

<< " ^ number to power" << endl

<< " ! factorial" << endl

<< " q quit" << endl << endl;

cout<< "Next Operation? "<

cin>>operation;

switch(operation){ //switch is added here

case '+':{ // + is for addition

int number1, number2;

cout<<"What is the first number to add?"<

cin>>number1;

cout<<"What is the second number to add?"<

cin>>number2;

cout<

break;

}

case '-':{ // - is for substraction

int number1, number2;

cout<<"What is the first number to subtract?"<

cin>>number1;

cout<<"What is the second number to subtract?"<

cin>>number2;

cout<

break;

}

case '*':{ // * for multiplication

int number1, number2;

cout<<"What is the first number to multiiply?"<

cin>>number1;

cout<<"What is the second number to multiply?"<

cin>>number2;

cout<

break;

}

case '/':{ // '/' for division

int number1, number2;

cout<<"What is the first number to dividend?"<

cin>>number1;

cout<<"What is the second number to divisor?"<

cin>>number2;

cout<

cin>>number1;

cout<<"What is the power?"<

cin>>number2;

cout<

break;

}

case '!':{ // factorial

int number;

cout<<"What is the number?"<

cin>>number;

cout<< number << "!" << "="<

break;

}

case 'q':{ // quits program

return 0;

}

}

cout<< "Next Operation? "<

}

return 0; //This is to make sure that the program terminates

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions