Create a Console based Calculator in C#.
- Every team forks this repo (then each team member clones your fork).
- There should be Unit Tests on all classes and methods you create.
- Your solution should have at least 2 total projects. Unit Tests should be in it's own project.
- This is an OOP focused class. Therefore, there will be classes. Your
Program
class andMain
method should only be responsible for receiving user input and printing output. - If a user submits an incomplete command or expression, the calculator should not attempt to evaluate it but print out a useful message.
Starting your console application should create a prompt that looks like:
[x]>
where x
is the number of executed commands/expressions during the user's current session. Call this your "counter".
On startup, your initial prompt should always look like:
[0]>
The user will enter simple mathematical expressions or commands. The user pressing [Enter] will have the calculator print out the correct answer on the following line (prefixed with an =
). After the answer is printed, the user should return to the original prompt.
For example, below the user entered 2+1
, then pressed [Enter]. The calculator printed out the answer 3
and reprinted the prompt, waiting for input from the user.
[0]> 2+1
= 3
[1]>
Further use of this session will again increment the counter part of the prompt:
[1]> 1-10
= -9
[2]>
Finally, typing exit
or quit
should exit the program while printing a message:
[2]> exit
Bye!!
Your calculator should following operations
- addition (integer)
- subtraction (integer)
- integer division (integer)
- modulus (integer)
- multiplication (integer)
In addition to math expressions, your calculator should accept the following commands:
quit
andexit
- exits the programlast
- prints the last printed answerlastq
- prints the last entered command or expression
For the chosen few, you get the implement the concept of 'constants' in the caluculator. See below for how it should work:
[0]> x = 3
= saved 'x' as '3'
[1]> x
= 3
[2]> 1 + x
= 4
[3]> x = 4
= Error!
- Any lowercase letter of the alphabet can be a constant.
- Calculator should be case insensitive.
A
is considered the same asa
. - Constants can only be defined once per session.
- Defined constants can be used in math expressions
- Using undefined constants should result in a printed a helpful message noting the constant is undefined.
Read GUIDANCE for assistance on progressing through the project