Simulates the core logic of a calculator, showing how user input is built into an expression string and evaluated.

ID: 1365

				
					using uCalcSoftware;

var uc = new uCalc();
string display_text = "";

// Simulate user pressing buttons: 1, 2, 3, +, 4, 5, 6
display_text = display_text + "123";
Console.WriteLine($"Display: {display_text}");

display_text = display_text + "+";
Console.WriteLine($"Display: {display_text}");

display_text = display_text + "456";
Console.WriteLine($"Display: {display_text}");

// Simulate pressing '='. This is where uCalc does the work.
var result = uc.EvalStr(display_text);
display_text = result;
Console.WriteLine($"Result: {display_text}");

Console.WriteLine("");

// Simulate a new calculation with an error
display_text = "5 * / 3";
Console.WriteLine($"Display: {display_text}");
result = uc.EvalStr(display_text);
display_text = result;
Console.WriteLine($"Result: {display_text}");

Console.WriteLine("");

// Simulate clearing the display
display_text = "C"; // Let's say 'C' is a special command
if (display_text == "C") {
   display_text = "";
}
Console.WriteLine($"Display after clear: '{display_text}'");
				
			
Display: 123
Display: 123+
Display: 123+456
Result: 579

Display: 5 * / 3
Result: Syntax error

Display after clear: ''
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   string display_text = "";

   // Simulate user pressing buttons: 1, 2, 3, +, 4, 5, 6
   display_text = display_text + "123";
   cout << "Display: " << display_text << endl;

   display_text = display_text + "+";
   cout << "Display: " << display_text << endl;

   display_text = display_text + "456";
   cout << "Display: " << display_text << endl;

   // Simulate pressing '='. This is where uCalc does the work.
   auto result = uc.EvalStr(display_text);
   display_text = result;
   cout << "Result: " << display_text << endl;

   cout << "" << endl;

   // Simulate a new calculation with an error
   display_text = "5 * / 3";
   cout << "Display: " << display_text << endl;
   result = uc.EvalStr(display_text);
   display_text = result;
   cout << "Result: " << display_text << endl;

   cout << "" << endl;

   // Simulate clearing the display
   display_text = "C"; // Let's say 'C' is a special command
   if (display_text == "C") {
      display_text = "";
   }
   cout << "Display after clear: '" << display_text << "'" << endl;
}
				
			
Display: 123
Display: 123+
Display: 123+456
Result: 579

Display: 5 * / 3
Result: Syntax error

Display after clear: ''
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim display_text As String = ""
      
      '// Simulate user pressing buttons: 1, 2, 3, +, 4, 5, 6
      display_text = display_text + "123"
      Console.WriteLine($"Display: {display_text}")
      
      display_text = display_text + "+"
      Console.WriteLine($"Display: {display_text}")
      
      display_text = display_text + "456"
      Console.WriteLine($"Display: {display_text}")
      
      '// Simulate pressing '='. This is where uCalc does the work.
      Dim result = uc.EvalStr(display_text)
      display_text = result
      Console.WriteLine($"Result: {display_text}")
      
      Console.WriteLine("")
      
      '// Simulate a new calculation with an error
      display_text = "5 * / 3"
      Console.WriteLine($"Display: {display_text}")
      result = uc.EvalStr(display_text)
      display_text = result
      Console.WriteLine($"Result: {display_text}")
      
      Console.WriteLine("")
      
      '// Simulate clearing the display
      display_text = "C" '// Let's say 'C' is a special command
      If display_text = "C" Then
         display_text = ""
      End If
      Console.WriteLine($"Display after clear: '{display_text}'")
   End Sub
End Module
				
			
Display: 123
Display: 123+
Display: 123+456
Result: 579

Display: 5 * / 3
Result: Syntax error

Display after clear: ''