Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

{//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

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));

}

HERES AN EXAMPLE OF WHAT IT SHOULD LOOK LIKE

image text in transcribed

WELCOME TO THE CALCULATOR PROJECT A.) Addition B.) Subtraction C.) Multiplication D.) Division E.) Roots (only positive number) F.) Power (only positive number) G.) Percentage H.) Least Common Multiplier I.) Greatest Common Divisor J.) Modulus K.) Display function execution* L.) Quit Please select an operation: A Please provide the first number: 2 Please provide the second number: 3 Operation: 2 + 3- 5 WELCOME TO THE CALCULATOR PROJECT A.) Addition B.) Subtraction C.) Multiplication D.) Division E.) Roots (only positive number) F.) Power (only positive number) G.) Percentage H.) Least Common Multiplier I.) Greatest Common Divisor J.) Modulus K.) Display function execution* L.) Quit Please select an operation

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

What is an addressed uncertainty in Project Risk Management?

Answered: 1 week ago

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago