Due: Tuesday, October 12 by 11:59PM

Overview

For this assignment, re-write program 4 so that it uses functions.

A menu of different calculations will be shown to a user at the beginning of the program (and again after each calculation). The user will select an option and the program will then prompt for additional information that is specific to the calculation, perform the actual calculation, and display the result. This process will continue until the user decides to quit.

The Arithmetic Calculations

The calculations that will be available to the user are:

finding the larger of two real numbers

determining if one integer number is divisible by another integer number

finding the range of four real numbers. The range is the difference between the largest and smallest of the four numbers.

raising a real number (M) to an integer power (N) - M to the Nth power

calculating the factorial of an integer number. The factorial is the product of all integers from 1 to the integer. The exception is 0! which is equal to 1.

Limits

One thing that will be different for this assignment is that there are limits on the values that will be used in the various calculations.

When finding the larger of two real numbers, the two numbers should be between -999.99 and 999.99

When determining if one integer number is divisible by another integer number, the dividend should be between 0 and 1000 while the divisor should be between 1 and 50

When finding the range of the four real numbers, the numbers should all be between -100.00 and 100.00

When raising a real number (M) to an integer power (N) - M to the Nth power - the M value should be between 1.00 and 100.00 while the N value should be between 1 and 10

When calculating the factorial of an integer number, the number should be between 0 and 14

Logic for main()

Display a menu to the user and get their choice by calling the menu() function

While the user does not want to quit

If the user wants to find the larger of two numbers

Call the doLarger() function

Else if the user wants to determine if a number is divisible by another number

Call the doDivisble() function

Else if the user wants to find the range of a set of numbers

Call the doRange() function

Else if the user wants to raise a number to the power

Call the doPower() function

Else (the user wants to calculate a factorial)

Call the doFactorial() function

Endif

Display a menu to the user and get their next choice by calling the menu() function
Endwhile

The Functions

The following functions are required for this assignment:

This function displays a menu to the user. It will then accept the user's choice (as a character) and check it for validity - that is did the user enter a 'l' or 'L' or 'd' or 'D' or 'r' or 'R' etc... If not, an error message should be displayed and the user should be given another chance to make a choice - this should continue until the user enters a valid value. Once a valid choice is made, the character should be returned to the calling function (main()). The menu should resemble the following:

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do?

int getInteger( string prompt, int lowerBound, int upperBound )

This function will get an integer value from the user that is within a specified range. It takes three arguments: a string that will be part of the prompt that is displayed to the user, and two integers that represent the lower and upper bound for a specified range. It returns an integer value that is within the specified range.

The function should display a prompt to the user and accept a value. If the value is within the range, it should be returned to the calling function. If the value is invalid, display an error message and ask the user to to re-enter a value - this should be repeated until a valid value is entered.

A calling statement like:

value = getInteger( "Enter the N-value", 1, 10 );
should produce the following prompt to the user:

Enter the N-value (1 - 10):

double getReal( string prompt, double lowerBound, double upperBound )

This function will get a double value from the user that is within a specified range. It takes three arguments: a string that will be part of the prompt that is displayed to the user, and two doubles that represent the lower and upper bound for a specified range. It returns a double value that is within the specified range.

The function should display a prompt to the user and accept a value. If the value is within the range, it should be returned to the calling function. If the value is invalid, display an error message and ask the user to to re-enter a value - this should be repeated until a valid value is entered.

A calling statement like:

value = getReal( "Enter the 1st range value", -100, 100 );
should produce the following prompt to the user:

Enter the 1st range value (-100 - 100):

void doLarger()

This function will perform the steps that are necessary to find and display the larger of two double numbers. It should call the getReal() function two times to get the two double numbers that will be compared, the two double numbers should be passed to the calcLarger() function, and then the larger of the two numbers should be displayed.

double calcLarger( double num1, double num2 )

This function will find the larger of two double numbers. It takes two arguments: the two double values that will be used in the comparison; and returns the larger of the two values.

void doDivisible()

This function will perform the steps that are necessary to determine whether one integer is divisible by another integer. It should call the getInteger() function two times to get the two integers (the dividend and divisor), the two integers should be passed to the isDivisible() function, and then a statement as to whether or not the dividend is evenly divisible by the divisor should be displayed.

bool isDivisible( int dividend, int divisor )

This function will determine if a number is evenly divisible by another number. It takes two arguments: the integer dividend and the integer divisor; and returns true if the dividend is evenly divisible by the divisor or false if it is not evenly divisible.

void doRange()

This function will perform the steps that are necessary to find and display the range of four double numbers. It should call the getReal() function four times to get the four double numbers, the four double numbers should be passed to the calcRange() function, and then the calculated range should be displayed.

double calcRange( double num1, double num2, double num3, double num4 )

This function will find the range of four double numbers. It takes four arguments: the four double values to find the range of; and returns the range of the values.

void doPower()

This function will perform the steps that are necessary to raise a number to a power and display the result. It should call the getReal() function to get the M value, call the getInteger() function to get the N value, those values should be passed to the calcMtoN() function, and then the result should be displayed.

double calcMtoN( double M, int N )

This function will calculate the result of raising M to the Nth power. It takes two arguments: the double M value and the integer N value to use in the calculation; and returns the result of raising M to the Nth power.

void doFactorial()

This function will perform the steps that are necessary to calculate and display the factorial of a number. It should call the getInteger() function to get the integer to use in the factorial calculation, the integer should be passed to the calcFactorial() function, and the factorial should be displayed.

int calcFactorial( int number )

This function will calculate the factorial of an integer. It takes one argument: the integer number to use in the factorial calculation; and returns the factorial of the number.

Program Requirements

Create and use four symbolic constants. They should represent the minimum and maximum values for the calculations of your choice.

The values inputted by the user for determining divisibility, N power value, and the factorial should be data type int. The values for determining the maximum of two numbers, range, and M value should be data type float or double.

The float/double results should be displayed with exactly 2 digits after the decimal point, including zeros.

At the top of your C++ source code, include a documentation box that resembles the ones from the previous programs.

Complete program documentation is required from this assignment. Include line documentation and function documentation boxes. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. See the documentation standards on the course webpage.

Make sure and test the program with values other than the ones supplied in the sample output that follows. Especially be sure to test invalid menu choices.

Hand in a copy of the source code (CPP file) using Blackboard.

Sample Output

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? L

Enter the first real number (-999.99 - 999.99): 11

Enter the second real number (-999.99 - 999.99): 30

30.00 is the larger number.

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? m

***** INVALID SELECTION *** Choose again from (L, D, R, P, F, or Q): t

***** INVALID SELECTION *** Choose again from (L, D, R, P, F, or Q): T

***** INVALID SELECTION *** Choose again from (L, D, R, P, F, or Q): P

Enter the M value (1.00 - 100.00): 2

Enter the power (1 - 10): 14

14 is invalid. The value must be between 1 and 10. Try again: -4

-4 is invalid. The value must be between 1 and 10. Try again: 4

29.00 raised to the power of 4 is 707281.00

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? d

Enter the dividend (0 - 1000): 94

Enter the divisor (1 - 50): 4

94 IS NOT divisible by 4

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? D

Enter the dividend (0 - 1000): 348

Enter the divisor (1 - 50): 3

348 IS divisible by 3

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? R

Enter the first real number (-100.00 - 100.00): 12.3

Enter the second real number (-100.00 - 100.00): 98.7

Enter the third real number (-100.00 - 100.00): 7.41

Enter the fourth real number (-100.00 - 100.00): 95.1

The range of 12.30, 98.70, 7.41 and 95.10 is 91.29

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? f

Enter the factorial number (0 - 14): 6

The factorial of 6 is 720

Make a selection from the list below.

L) Determine the 'L'arger of 2 real numbers
D) Check if an integer is 'D'ivisible by another integer
R) Find the 'R'ange of a set of 4 real numbers
P) Find the value of the expression, M to the Nth 'P'ower
F) Find the value of a 'F'actorial

Q) 'Q'uit

What would you like to do? q