Question: c++ For this project, you are required to build a simple calculator simulator in C++. You are required to implement all operations (explained in this

c++

For this project, you are required to build a simple calculator simulator in C++.

You are required to implement all operations (explained in this document) as separate functions. Each function will be responsible for one mathematical operation. C++ has a very convenient mathematical library, but unfortunately you cannot use it. So, you need to write your own function for each operation. The code for the functions that implement root, power, LCM (least common multiple), and GCD (great common divisor) is given at the end of this document. You are ALLOWED to copy and paste those functions into your project and use them.

The user must choose which operation she/he will perform based on a menu option displayed. Once an operation is selected and performed the program should again display the menu. This shall happen until the user selects the quit option. It is required to display a welcome message when the program starts and exit message when exiting. Both must be implemented as functions that return the messages as strings. If no correct menu option is selected the user will be asked for a valid input until they do so.

Operations: addition, subtraction, multiplication, division, roota, powerb, percentagec, least common multipled, greatest common divisord and modulus;

a = The user must specify the number and the nth-root desired: see algorithm in the end of this document.

b = the user must specify the exponent an , where a and n will be provided by the user, and must be positive

c = in the format of X% of N, where N is a number and X the requested percentage of that number (It is up to you how to handle the input, as long it is correct)

d= assume that these operations work only with positive integers

Constraints:

Root/Power operations shall not work with negative numbers the user must be notified of that and ask for a new input until a proper one is provided.

Division - there is no division by 0 (zero) the user must be notified of that and ask for a new input.

All the operations, except where specified, must work for any Real number.

Every function (including main) must contain: Author name, creation date, last modification date, purpose (standard comment headers).

DO NOT use math libraries (e.g. math.h, cmath) This will result in a 75% penalty.

No global variables are allowed except constants

No functions (except main, menu, and display menu execution option) should have any input or output statements.

Below are four functions you can copy and paste. You are required to write the code for the other functions and the main (you still need to write the comments before each function). Make sure you fix any compilation error you may find in the functions below.

float computeRoot(float root, int index)

{

float tp, mid, low = 0.0, high = root;

do {

mid = (low + high) / 2;

if (Power(mid, index) > root)

high = mid;

else

low = mid;

mid = (low + high) / 2;

tp = (Power(mid, index) - root);

if (tp < 0)

{//grab absolute value

tp = -tp;

}

}

while (tp > .000005); //accuracy of our root

return mid;

}

float computePower(float x, int n)

{

float numProduct = 1.0;

int i;

for (i = 0; i < n; i++)

numProduct *= x;

return numProduct;

}

int computeGCD(int a, int b)

{

while (a != b)

{

if (a > b)

a -= b;

else

b -= a;

}

return a;

}

int computeLCM(int a, int b)

{

//int tmp_lcm;

//tmp_lcm = ((a * b) / GCD(a, b));

//return tmp_lcm;

return ((a * b) / GCD(a, b));

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!