diff --git a/FusionCalculator b/FusionCalculator
index 2a4f92f..7dab069 160000
--- a/FusionCalculator
+++ b/FusionCalculator
@@ -1 +1 @@
-Subproject commit 2a4f92fe351882a489c330ba82504d319df14c73
+Subproject commit 7dab069aa6c58ea4a5270e8983663076eb35dbf2
diff --git a/SharpCalculator.Avalonia/App.axaml b/SharpCalculator.Avalonia/App.axaml
index ebcd339..070776c 100644
--- a/SharpCalculator.Avalonia/App.axaml
+++ b/SharpCalculator.Avalonia/App.axaml
@@ -15,7 +15,6 @@
-
diff --git a/SharpCalculator.Avalonia/MainWindow.axaml b/SharpCalculator.Avalonia/MainWindow.axaml
index 9966e39..1430423 100644
--- a/SharpCalculator.Avalonia/MainWindow.axaml
+++ b/SharpCalculator.Avalonia/MainWindow.axaml
@@ -4,148 +4,158 @@
x:Class="SharpCalculator.Avalonia.MainWindow"
Title="SharpCalculator"
FontFamily="Consolas" FontSize="24"
- Width="600" Height="750"
- MinWidth="600" MinHeight="750">
+ Width="460" Height="570">
-
- * * * * * * *
+
+ 1* 40 1* 330
- * * * * * * * * * *
-
-
-
-
-
-
-
-
-
-
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+ * * * * * * *
+ * * * * *
+
+
+
+
-
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
\ No newline at end of file
diff --git a/SharpCalculator.Avalonia/MainWindow.axaml.cs b/SharpCalculator.Avalonia/MainWindow.axaml.cs
index 4f7313d..f2452e2 100644
--- a/SharpCalculator.Avalonia/MainWindow.axaml.cs
+++ b/SharpCalculator.Avalonia/MainWindow.axaml.cs
@@ -4,29 +4,24 @@ namespace SharpCalculator.Avalonia;
public partial class MainWindow : Window
{
- private static readonly Random Random = new();
- private readonly List _history = new(); // History list to append expressions
+ private readonly Random Random = new();
public MainWindow()
{
InitializeComponent();
}
- private void AppendToHistory(string calculation) //function of appending expression to the history list
+ private void AppendToHistory(string line) //function of appending expression to the history list
{
- _history.Add(calculation);
- UpdateHistoryText();
- }
-
- private void UpdateHistoryText() //function to update history list
- {
- int lastIndex = _history.Count - 1;
- if (lastIndex >= 0)
- History1.Text = _history[lastIndex];
- if (lastIndex - 1 >= 0)
- History2.Text = _history[lastIndex - 1];
- if (lastIndex - 2 >= 0)
- History3.Text = _history[lastIndex - 2];
+ // begin new line if not empty
+ if (!string.IsNullOrEmpty(History.Text))
+ History.Text += '\n';
+ /// add line without space characters
+ History.Text += line
+ .Replace("\t", " ")
+ .Replace("\n", " ")
+ .Replace("\r", " ")
+ .Replace(" ", " ");
}
private void MathButton_OnClick(object? sender, RoutedEventArgs e)
@@ -34,39 +29,30 @@ public partial class MainWindow : Window
if (sender is not Button button)
throw new Exception();
- switch (Input.Text) // Switch case for checking the inputting functions
+ string buttonText = button.Content!.ToString()!; // declaring text for using it in switch case
+ Input.Text += buttonText switch
{
- case "rand": // rand function add random variable from 0 to 1 into Input
- Input.Text = "";
- Input.Text += Random.NextDouble().ToString(CultureInfo.InvariantCulture);
- break;
- case "π": // Pi function add pi value into Input
- Input.Text = "";
- Input.Text += "3.1415";
- break;
- case "e": // euler function add e value into Input
- Input.Text = "";
- Input.Text += "2.71828";
- break;
- case "10^x": // ten in power of x function
- Input.Text = "";
- Input.Text += "10^";
- break;
- case "1/x": // one over x function
- Input.Text = "";
- Input.Text += "1/";
- break;
- default: // if there is no function input, then just input Button content
- string text = button.Content!.ToString()!; // declaring text for using it in switch case
- Input.Text += text;
- break;
- }
+ "rand" => // random number from 0 to 1 into Input
+ Random.NextDouble().ToString("0.#####", CultureInfo.InvariantCulture),
+ "π" => // Pi constant
+ "3.14159",
+ "e" => // E constant
+ "2.71828",
+ "10^x" => // ten in power of x function
+ "10^",
+ "1/x" => // one over x function
+ "1/",
+ "sin" or "cos" or "tg" or "ctg"
+ or "asin" or "acos" or "atg" or "actg"
+ or "ln" => buttonText+'(',
+ _ => buttonText
+ };
}
-
private void ClearButton_OnClick(object? sender, RoutedEventArgs e)
{
Input.Text = "";
+ Output.Text = "";
}
private void UndoButton_OnClick(object? sender, RoutedEventArgs e)
@@ -78,6 +64,16 @@ public partial class MainWindow : Window
}
private void ResultButton_OnClick(object? sender, RoutedEventArgs e)
+ {
+ if(Input.Text == null || Output.Text == null || Output.Text.StartsWith("Error"))
+ return;
+ string expression = Input.Text;
+ string result = Output.Text;
+ AppendToHistory($"{expression}={result}");
+ Input.Text = result;
+ }
+
+ private void Input_OnTextChanged(object? sender, TextChangedEventArgs e)
{
if(Input.Text == null)
return;
@@ -85,16 +81,19 @@ public partial class MainWindow : Window
string exprStr = Input.Text; // mathematical expression
try
{
- double result = Calculator.Calculate(exprStr); // result being processed by calculator object that implemented in FusionCalculator Module
- if (!double.IsNaN(result))
- {
- AppendToHistory($"{exprStr} = {result}");
- Input.Text = result.ToString(CultureInfo.InvariantCulture);
- }
+ // expression is being processed by Calculator class that implemented in FusionCalculator Module
+ double result = Calculator.Calculate(exprStr);
+ if (double.IsNaN(result))
+ Output.Text = "";
+ // scientific notation with 5-digit precision for big and small numbers
+ else if (result > 10e+15 || result < 10e-5)
+ Output.Text = result.ToString("0.#####E0", CultureInfo.InvariantCulture);
+ // decimal number with 5-digit precision for regular numbers
+ else Output.Text = result.ToString("0.#####", CultureInfo.InvariantCulture);
}
catch (Exception exception)
{
- AppendToHistory($"Error: {exception.Message}");
+ Output.Text = $"Error: {exception.Message}";
}
}
}
\ No newline at end of file