Sharp Calculator : Visual C#
Earlier we had published a Visual C++ project titled Standard Calculator. The current project i.e. the Sharp Calculator contains the same project developed using Visual C#. Therefore, it performs the same tasks as the Standard Calculator. The only difference lies in the syntax of certain statements (and minor UI changes).
The following screenshots describe the functionality of the Sharp Calculator :-
Sharp Calculator vs Standard Calculator – Differences
As you know, Visual C++ CLR and Visual C# are nearly identical. Therefore, the code for the current project and the Visual C++ version is also nearly identical save a few remarkable differences.
For example, the Visual C++ program uses the following statement to write to the first text box.
tbinput1->Text = System::Convert::ToString(tby);
On the other hand, the Visual C# program uses the following statement to write to the first text box.
textBox1.Text = System.Convert.ToString(tby);
As you can see above, Visual C++ uses the -> operator for accessing and modifying the text contained in the text box while Visual C# uses the . operator for the same task. Also, Visual C# uses the . operator instead of the :: used by Visual C++.
Another difference in the source code of these two programs is that while the Visual C++ version uses int(number) format of type-casting, the Visual C# version uses (int)number. This is because int(number) doesn’t work in Visual C#.
Sharp Calculator in Action
The following video illustrates the functionality of the current Calculator project. The following video shows the Standard Calculator but the Sharp Calculator works just the same (since the current project is identical to the Visual C++ version) :
Please Note that this program suffers from a bug. As long as you use only whole numbers as operands, all works well. However, if you try to enter a floating point number (using the ‘.’ button in the UI of the program) that has more than one digit after the decimal, it messes up the number. This happens because the dot (.) button hasn’t been configured properly in this program.
Fortunately, there’s a very simple workaround. Just type the dot (.) using the keyboard instead of using the ‘.’ button in the program.