I included a picture of the program structure to follow.....Note that full point
ID: 3567684 • Letter: I
Question
I included a picture of the program structure to follow.....Note that full points will be awarded only if you follow the procedure from the picture
thanks
The program shall consist of two .cpp files: Lab09.cpp and MyMath.cpp. There shall also be one .hpp file named MyMath.hpp.
The program shall display a menu with three menu items,
What would you like to do?
1. Compute the a-th root of a number.
2. Compute the n-th Fibonacci number.
3. Quit the program.
Choice? 1
and prompt the user to select menu item 1, 2, or 3. If the user selects menu item 1, the program shall prompt the user to enter
values for n and a,
Your choice is to compute the a-th root of n.
Enter n (>= 0): 13512
Enter a (>= 2): 5
The 5-th root of 13512.0000000000000000 is 6.7010664923861052
and it shall compute and display the a
th root of n (configure cout to display real number in fixed notation with 16 digits after the
decimal point). After displaying the result, the program shall display the menu again,
What would you like to do?
1. Compute the a-th root of a number.
2. Compute the n-th Fibonacci number.
3. Quit the program.
Choice? 2
and prompt the user to select menu item 1, 2, or 3. If the user selects menu item 2, it shall prompt the user to enter a value for n,
Your choice is to compute the n-th Fibonacci number.
Enter n (>= 0): 22
The 22-th Fibonacci number is 17711
and shall display the n
th Fibonacci number. After displaying the result, the program shall display the menu again. It shall continue this
process of displaying the menu, performing the selected operation when menu items 1 or 2 are selected. When the user selects
menu item 3, the program shall terminate,
What would you like to do?
1. Compute the a-th root of a number.
2. Compute the n-th Fibonacci number.
3. Quit the program.
Choice? 2
Your choice is to compute the n-th Fibonacci number.
Enter n (>= 0): 22
The 22-th Fibonacci number is 17711
What would you like to do?
1. Compute the a-th root of a number.
2. Compute the n-th Fibonacci number.
3. Quit the program.
Choice? 2
Your choice is to compute the n-th Fibonacci number.
Enter n (>= 0): 46
The 46-th Fibonacci number is 1836311903
What would you like to do?
1. Compute the a-th root of a number.
2. Compute the n-th Fibonacci number.
3. Quit the program.
Choice? 3
Bye.
HERE RS THE PROCEDURE (PLEASE SEPARATE THE Two CPP FLES AND THE HPP FILES WITH A--- LINE) Function Hain() Returns Int Configure cout to display real numbers in fixed ootation vith 16 digits arter the decital point choice Menu() While choice is not equal to 3 Do If choice equals i Then Compute thRoot() ComputeNthFib() End If choice Nenuo End While Send "Bye." to cout Return 0 End Function main Function computelthRoot() Returns Nothing Print a blank line Send "Your choice is to compute the a-th root of a number to cout n Get Doubler Enter n 0): e) a Get Int("Enter a 2) Toot AthRoot(n, a, 1E-16) Send "The a r-th root of n is root to cost Print a blank line End Function ComputelthRoot Function compute thFib() Returns Nothing Print a blank line n Get Int("Enter n 0) Fab(n) fib n Send "The n th Fibonacci number 1s fib-n to cost Print a blank line End Function ComputeNthFib Function GetDouble(pPrompt is a string) Returns Double Send pProapt to cout Read a double frot the Zeyboard into n Return n End Function GetDouble() Function Getint (pPrompt is a string) Returns Integer Send p Prompt to cout Read an integer froa the keyboard into n Return n End Function Get Int() Function Menu() Returns Int Send "What would you like to do?" to cott Send "1. Compute the a-th root of a number to cout Send "2. Corpute the n-th Fibonacci number." to cout Send "3. quit the program. to cout ena ice Getint Choice? Return choice End Function Menu tifadef HYMATH EPP #define MYMATH EPP double AthRoot(double a, int a, double epsiloa) int Fit (int n);Explanation / Answer
/********************
* Lab09.cpp *
********************/
#include <iostream>
#include <MyMath.hpp>
#include <iomanip>
#include <cstring>
using namespace std;
int main()
{
cout << setprecision(16);
int choice;
choice = menu();
while(choice != 3)
{
if(choice == 1)
{
computeAthRoot();
}
else
{
computeNthFib();
}
choice = menu();
}
cout << "Bye." << endl;
return 0;
}
void computeAthRoot()
{
cout << endl;
cout << "Your choice is to compute the a-th root of a number.";
double n = getDouble("Enter n (>= 0) : ");
int a = getInt("Enter a (>= 2) : ");
double root = AthRoot(n, a);
cout << "The " << a << "-th root of " << n << " is " << root << endl;
cout << endl;
}
void computeNthFib()
{
cout << endl;
int n = getInt("Enter a (>= 0) : ");
int fib_n = Fib(n);
cout << "The " << n << "-th Fibonacci number is " << fib_n << endl;
cout << endl;
}
double getDouble(string pPrompt)
{
cout << pPrompt;
double n;
cin >> n;
return n;
}
int getInt(string pPrompt)
{
cout << pPrompt;
int n;
cin >> n;
return n;
}
int menu()
{
cout << "What would you like to do?" << endl;
cout << "1. Compute the a-th root of a number." << endl;
cout << "2. Compute the n-th Fibonacci number." << endl;
cout << "3. Quit the program." << endl;
int choice = getInt("Choice? ");
return choice;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****************
* MyMath.hpp *
****************/
#ifndef MYMATH_HPP
#define MYMATH_HPP
double AthRoot(double n, int a);
int Fib(int n);
#endif
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
/****************
* MyMath.cpp *
****************/
#include <cmath>
double AthRoot(double n, int a)
{
double root = pow(n, 1/a);
return root;
}
int Fib(int n)
{
int i = 0;
int fib_n = 1;
for(int j = 2; j <= n; j++)
{
int temp = i + fib_n;
i = fib_n;
fib_n = temp;
}
return fib_n;
}