Question Simple calculator for an interview

erossini

New member
Joined
May 21, 2021
Messages
3
Programming Experience
10+
I want to create a simple test for a calculator. I saw some code in PHP on GitHub and from it I think the name of this kind of calculator is Gorkana but I'm not sure. Also, I saw this is a popular topic on Stackoverflow :)

Basically, I want to create a C# project that calculate a result from a set of instructions. Instructions comprise a keyword and a number that are separated by a space per line. Instructions are loaded from file and results are output to the screen. Any number of Instructions can be specified.

Instructions can be any binary operators of your choice (e.g., add, divide, etc), ignoring mathematical precedence. The last instruction should be "apply" and a number (e.g., "apply 3").

The calculator is then initialised with that number and the previous instructions are applied to that number.

Two examples of the calculator lifecycle might be:

Example 1.​

[Input from file]
add 2
multiply 3
apply 3

[Output to screen]
15

[Explanation]
(3 + 2) * 3 = 15

Example 2.​

[Input from file]
multiply 9
apply 5

[Output to screen]
45

[Explanation]
5 * 9 = 45

How do you think I can face this project? Is there a source code in C# for it?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,555
Location
Chesapeake, VA
Programming Experience
10+
The point of an interview screening s to see how you think, how you break down a big problem into smaller problems, and then solve the small problems to come to a solution for the big problem.

Looking for a premade solution in GitHub or elsewhere, is not a good way to approach this. All you'll end up with is very likely one person's approach to solving the problem that you may or may not understand.

Programming is not like learning history (the classic way) of just spitting out an answer (dates, places, names). Yes, my sister, a History PhD would flog me for that statement. She'll tell me the modern way of learning history is about the context: the why, the social and economic pressures, the geography, etc. And the same is true for programming. It's not just the syntax or the code. It is about the data structures, algorithms, and techniques.
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,209
Location
Norway
Programming Experience
10+
Basic elements needed: Reading lines with File class and use String.Split method. Switch statement to interpret operation.
Basic algorithm: Take last line (apply) and set start value. Loop the other lines except last and calculate result each step.
 

erossini

New member
Joined
May 21, 2021
Messages
3
Programming Experience
10+
I got your point. I have started to create and sell software when I was 4yo, I have worked for the bigger companies in Europe. I don't want to waste my time to write test that companies won't check or always mark "you didn't do this or that". Unfortunately, the majority of the people doesn't know what "programming" or "coding" mean. They don't have real experience of coding in the real world. They have just read in some university book test...
 

erossini

New member
Joined
May 21, 2021
Messages
3
Programming Experience
10+
This is too simple. I have some feedback on someone who previously took the test, and this was the feedback from the technical team.
  • hasn’t used DI or Single Responsibility
  • Hasn’t accounted for division by zero!
  • Code is just to get the job done
  • Implemented his own IsNullOrEmpty method which seems a bit pointless
They want to fire at the bird with a cannon. I don't know what the model is ;)
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,555
Location
Chesapeake, VA
Programming Experience
10+
If you have that much industry experience, I recommend writing the code for the calculator the way you would like to see the code when you are reviewing it 1 or 2 years from now. You don't have to cater to someone else whims about how they want the code to be written.
 
Top Bottom