Calculator
Program a calculator that adds, substracts, multiplies and divides two real numbers. The user will introduce a binary mathematical expression (such as 3.5 + 2.2
) and the program will calculate the result and show it on screen (e.g. 4.7
).
The program will interactivelly ask for expressions until one expression has two zero operands. In the case of a division by zero, the program will output an error and keep asking for expressions.
Execution example:
> 3.5 + 2.2
4.7
> 2 x 4
8
> 5.5 / 0
Error: division by zero
> 0 - 0
End
Experiment with different executions, try to break it by entering non-standard calculator expressions, and see what happens with the output. You will realize that it is actually very easy to break if you do not follow the standard format number operator number. At this moment this is something that you do not need to solve.
Submission
The source code that solves the proposed problem should be in a file named calculator.cpp
that should compile with the commandline:
g++ calculator.cpp -o calculator
Before submitting, remember to talk to your teacher and have a small interview describing and answering questions about the job you have done and the decissions you have made. This interview is 20% of the total grade of the assignment, while the submitted material is evaluated for the other 80%.
All source code files, must include a comment on top with the names and NIAs of the students involved on their development. Then, all source code files, including directory structure, must be compressed into a single zip
file with the following naming:
calculator_<nia1>_<nia2>.zip
, where<nia1>
and<nia2>
are the NIAs of the involved students, if the work has been done in pairs. In this case, only one of the students must submit the work in Moodle.calculator_<nia>.zip
, where<nia>
is the NIA of the involved student if the work has been done individually.
The compressed file must not contain anything else besides the source code files. Particularly, do not submit any binary file, neither executable, library nor object. The submission of the zip
file must be done through the corresponding task in Moodle before the stablished deadline.