Question: DESCRIPTION Main Menu Write a program that displays a menu as shown below. Mathematical Loops P - Calculate PI S - Calculate square root of
DESCRIPTION
Main Menu Write a program that displays a menu as shown below.
Mathematical Loops
P - Calculate PI
S - Calculate square root of 2
M - Print multiplication table
Q - quit
The program will continue to display the menu and execute the user's choice until the Quit option is selected. If the user makes an invalid selection, display a message (Invalid selection!) and present the menu again.
The user input should not be case sensitive, i.e., to exit the program, the user can type either Q or q.
Option P Calculating You will calculate an approximation of PI, using Wallis Formula:

Ask the user how many terms to multiply, use that input to control a for loop. Display your result.
You can assume the user will enter a non-negative number.
Option S Calculating Similarly, you will calculate an approximation of the square root of 2, using a variation of Wallis Formula:

{1,3,5,7,} (n is an odd positive integer)
Here, you will ask the user for an acceptable tolerance, which is a small real number, such as 0.01. Use a while loop and continue calculating until the square of your result is close enough to 2, within the given acceptable tolerance. Display your result for 2 and how many iterations it took.
You can assume the user will enter a non-negative number.
Option M Multiplication Table Print a multiplication table ranging from 1*1 up to n*n (where n is a number from 1 to 15), using proper formatting to make the columns legible. Use nested for loops for this.
You will ask the user for a number n (you can assume the user will enter a valid number from 1 to 15), then you will print the table. You should only show the lower half of the results, as in the example below, for n=12.
1 2 3 4 5 6 7 8 9 10 11 12 1 1 2 2 4 3 3 6 9 4 4 8 12 16 5 5 10 15 20 25 6 6 12 18 24 30 36 7 7 14 21 28 35 42 49 8 8 16 24 32 40 48 56 64 9 9 18 27 36 45 54 63 72 81 10 10 20 30 40 50 60 70 80 90 100 11 11 22 33 44 55 66 77 88 99 110 121 12 12 24 36 48 60 72 84 96 108 120 132 144
Option Q Quit the program Display a message (Program ending, goodbye.) and end the program.
REQUIREMENTS AND HINTS - Floating point values are to be displayed to 4 decimal digits. Use: cout
- Be sure to reset variables in each case as needed so that the options can be run more than once.
- You may (but are not required) to create one function for each item of the menu, but no more than that.
- Only mathematical functions, from cmath library, that are allowed are abs or fabs. No other math function or constants may be used.
- Remember: Menu selection is CASE INSENSITIVE.
- For the multiplication table, you may want to use setw to properly display the numbers with 5 characters. - Also for the multiplication table, do not use TAB for spaces.
- When calculating 2, avoid using numbers smaller than 0.001.
Transcribed image text
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
