Question
c++ Details For this lab, we are going to be working with functions from the math header library. Specifically, we are going to write a
c++
Details
For this lab, we are going to be working with functions from the math header library. Specifically, we are going to write a program that will accept a series of math functions followed by 1 or 2 numbers. Then we will output the function, the number arguments and the answer. If we are given unknown command we will also log that as well.
Input
The input will be a series of commands followed by 1 or two numbers. Only the raise-to-the-power command will have two numbers. All other commands will have 1 number. The commands correspond to the functions from the cmath header file. Essentially, we are you to read the command, decide what command was issued and call the corresponding function. Then you output the command, the arguments that were given and the answer. See the sample output below.
exponential 3.14 natural-log 10 log 10 raised-to-the-power 2.5 3 square-root 36.0 ceiling 43.2 floor 43.2 othercommand 10.0
There might be a single command in the file or there might be several. The input controlled failure loop is what we will be using to read until there are no more commands in the file. It is outlined below:
#include "lab5.h" void mathCalculator( string input, string output ) { ifstream in(input); ofstream out(output); string command; double argument1, argument2, answer; in >> command;//prime while( !in.fail() )//test { //process in >> command;//re-prime } }
While there are other ways to accomplish what we want, it is my experience that this is the best way to get this done. You dont have to use this, but if your code doesnt work Im going to ask why you didnt use what was given.
You will be adding the selection statement in the process section to determine the command and call the correct function.
Output
So if you are given the above input file, this is the corresponding output file.
Command Argument1 [Argument2] Answer exponential 3.14 23.1039 natural-log 10 2.30259 log 10 1 raised-to-the-power 2.5 3 15.625 square-root 36 6 ceiling 43.2 44 floor 43.2 43 Unknown command: othercommand
Now just a few words about the output. You do not need to match my spacing. Where I have space you must have at least one space. Where I dont have space, e.g. [Argument 2], you may not have space. I like my tables to look pretty so I took time to tab it out. You do not need to do this, unless you are like me and want it to look pretty. (The html made this look way worse then it does on Powershell.)
I have used the default number of decimal places on my doubles, you do not need to do anything to your output, e.g. setprecision, fixed or showpoint, to get this effect.
Requirements
1) You must use the header file lab5.h
2) In your lab5.h header file you must declare the function void mathCalculator( string input, string output );
3) Dont store the data, just process the data as it is read.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started