Добавлены операци:
SqrtY, Factorial, CubeRoot, Square, Cube, PowY, Log, Ln, Exp, Inv, Pi, Sinh, Sin, Cosh, Cos, Tanh, Tan
This commit is contained in:
parent
dcfd7c6e70
commit
d3836d6cfc
14 changed files with 1072 additions and 798 deletions
56
.gitignore
vendored
56
.gitignore
vendored
|
|
@ -360,4 +360,58 @@ MigrationBackup/
|
||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
.history/
|
||||||
|
*.vsix
|
||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/node_modules
|
||||||
|
/wwwroot/node_modules
|
||||||
|
*.tlog
|
||||||
|
*.vbp
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
.vshistory/
|
||||||
|
*.code-workspace
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
*.sln.iml
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
.idea/**/aws.xml
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
cmake-build-*/
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
*.iws
|
||||||
|
out/
|
||||||
|
.idea_modules/
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
.idea/replstate.xml
|
||||||
|
.idea/sonarlint/
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
.idea/httpRequests
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
|
||||||
6
.idea/.idea.calculator/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.calculator/.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
38
Commands/CalculateCommand.cs
Normal file
38
Commands/CalculateCommand.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
using calculator.Common;
|
||||||
|
using calculator.Model;
|
||||||
|
using calculator.Services;
|
||||||
|
|
||||||
|
namespace calculator.Commands;
|
||||||
|
|
||||||
|
public class CalculateCommand : ICommand
|
||||||
|
{
|
||||||
|
private readonly ICaculator _caculator;
|
||||||
|
private readonly CaculatorData _data;
|
||||||
|
private readonly double? _b;
|
||||||
|
private readonly Operation _operation;
|
||||||
|
private double? _previousValue;
|
||||||
|
|
||||||
|
public CalculateCommand(ICaculator caculator, CaculatorData data)
|
||||||
|
{
|
||||||
|
_caculator = caculator;
|
||||||
|
_data = data;
|
||||||
|
_operation = data.Operation.Value;
|
||||||
|
|
||||||
|
if (double.TryParse(data.Input, out var b))
|
||||||
|
_b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute()
|
||||||
|
{
|
||||||
|
if (_data.Value is null)
|
||||||
|
return;
|
||||||
|
_previousValue = _data.Value;
|
||||||
|
_data.Value = _caculator.Calculate(_operation, _data.Value.Value, _b);
|
||||||
|
_data.Input = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Undo()
|
||||||
|
{
|
||||||
|
_data.Value = _previousValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Commands/ICommand.cs
Normal file
7
Commands/ICommand.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace calculator.Commands;
|
||||||
|
|
||||||
|
public interface ICommand
|
||||||
|
{
|
||||||
|
void Execute();
|
||||||
|
void Undo();
|
||||||
|
}
|
||||||
32
Common/Operation.cs
Normal file
32
Common/Operation.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
namespace calculator.Common;
|
||||||
|
|
||||||
|
public enum Operation
|
||||||
|
{
|
||||||
|
Add,
|
||||||
|
Sub,
|
||||||
|
Mul,
|
||||||
|
Div,
|
||||||
|
Pow,
|
||||||
|
Sqrt,
|
||||||
|
SqrtY,
|
||||||
|
Factorial,
|
||||||
|
CubeRoot,
|
||||||
|
Square,
|
||||||
|
Cube,
|
||||||
|
PowY,
|
||||||
|
Log,
|
||||||
|
Ln,
|
||||||
|
Exp,
|
||||||
|
Inv,
|
||||||
|
Pi,
|
||||||
|
OneDiv,
|
||||||
|
Mod,
|
||||||
|
Neg,
|
||||||
|
Percent,
|
||||||
|
Sinh,
|
||||||
|
Sin,
|
||||||
|
Cosh,
|
||||||
|
Cos,
|
||||||
|
Tanh,
|
||||||
|
Tan
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
using calculator.Model;
|
using calculator.Commands;
|
||||||
|
using calculator.Common;
|
||||||
|
using calculator.Model;
|
||||||
using calculator.Services;
|
using calculator.Services;
|
||||||
using calculator.View;
|
using calculator.View;
|
||||||
|
|
||||||
|
|
@ -10,6 +12,7 @@ public class CaculatorController
|
||||||
private readonly IInputService _inputService;
|
private readonly IInputService _inputService;
|
||||||
private readonly ICaculatorView _view;
|
private readonly ICaculatorView _view;
|
||||||
private readonly CaculatorData _data;
|
private readonly CaculatorData _data;
|
||||||
|
private ICommand? _currentCommand;
|
||||||
|
|
||||||
public CaculatorController(ICaculator caculator, IInputService inputService, ICaculatorView view,
|
public CaculatorController(ICaculator caculator, IInputService inputService, ICaculatorView view,
|
||||||
CaculatorData data)
|
CaculatorData data)
|
||||||
|
|
@ -21,30 +24,22 @@ public class CaculatorController
|
||||||
|
|
||||||
_view.OperandPressed += OnOperandPressed;
|
_view.OperandPressed += OnOperandPressed;
|
||||||
_view.OperatorPressed += OnOperatorPressed;
|
_view.OperatorPressed += OnOperatorPressed;
|
||||||
_view.ClearPressed += OnFullClearPressed;
|
_view.ClearPressed += OnClearPressed;
|
||||||
_view.CalculatePressed += OnCalculatePressed;
|
_view.CalculatePressed += OnCalculatePressed;
|
||||||
_view.SingleOperatorPressed += OnSingleOperationPressed;
|
_view.SingleOperatorPressed += OnSingleOperationPressed;
|
||||||
OnFullClearPressed();
|
OnClearPressed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSingleOperationPressed(string obj)
|
private void OnSingleOperationPressed(Operation operation)
|
||||||
{
|
{
|
||||||
_data.Operation = null;
|
OnOperatorPressed(operation);
|
||||||
if (_data.Operands.Count == 2 && _data.Caculated == false)
|
_currentCommand = new CalculateCommand(_caculator, _data);
|
||||||
{
|
OnCalculatePressed();
|
||||||
OnCalculatePressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
_data.Caculated = true;
|
|
||||||
_data.SingleOperation = obj;
|
|
||||||
var operand = _data.Operands.Pop();
|
|
||||||
_data.Operands.Push(_caculator.SingleOperation(operand, obj));
|
|
||||||
_view.UpdateView(_data.Operands.Peek());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFullClearPressed()
|
private void OnClearPressed(bool full)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear(full: full);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCalculatePressed()
|
private void OnCalculatePressed()
|
||||||
|
|
@ -52,83 +47,70 @@ public class CaculatorController
|
||||||
if (_data.Operation is null)
|
if (_data.Operation is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_data.SingleOperation is not null)
|
if (_data.Value is null)
|
||||||
{
|
|
||||||
var singleOperand = _data.Operands.Pop();
|
|
||||||
_data.Operands.Push(_caculator.SingleOperation(singleOperand, _data.SingleOperation));
|
|
||||||
_view.UpdateView(_data.Operands.Peek());
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (_data.Operands.Count < 2)
|
if (_data is not { Caculated: true, Input: null } || _currentCommand == null)
|
||||||
{
|
{
|
||||||
var (lastOperand, lastOperation) = (_data.LastOperand, _data.Operation);
|
_currentCommand = new CalculateCommand(_caculator, _data);
|
||||||
if (lastOperand is not null && lastOperation is not null)
|
|
||||||
{
|
|
||||||
Calculate(_data.Operands.Pop(), lastOperand, lastOperation);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var operand = _data.Operands.Pop();
|
_currentCommand?.Execute();
|
||||||
var operand2 = _data.Operands.Pop();
|
|
||||||
Calculate(operand2, operand, _data.Operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Calculate(string operand1, string operand2, string operation)
|
|
||||||
{
|
|
||||||
_data.Caculated = true;
|
_data.Caculated = true;
|
||||||
_data.LastOperand = operand2;
|
UpdateView(_data.Value.Value);
|
||||||
_data.Operands.Push(_caculator.Calculate(operand1, operand2, operation));
|
|
||||||
_view.UpdateView(_data.Operands.Peek());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Clear(string value = "0", bool full = true)
|
private void Clear(string value = "0", bool full = true)
|
||||||
{
|
{
|
||||||
if (full)
|
if (full)
|
||||||
{
|
{
|
||||||
_data.Operands.Clear();
|
_data.Value = null;
|
||||||
_data.Operation = null;
|
_data.Operation = null;
|
||||||
_data.SingleOperation = null;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
_data.Operands.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
_data.Caculated = false;
|
_data.Caculated = false;
|
||||||
_data.LastOperand = null;
|
_data.Input = null;
|
||||||
_data.Operands.Push(value);
|
_view.UpdateView(value);
|
||||||
_view.UpdateView(_data.Operands.Peek());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOperatorPressed(string operation)
|
private void OnOperatorPressed(Operation operation)
|
||||||
{
|
{
|
||||||
_data.SingleOperation = null;
|
if (_data.Input == null && _data.Value == null)
|
||||||
if (_data.LastOperand is not null && _data.Caculated == false)
|
return;
|
||||||
|
|
||||||
|
if (_data is { Caculated: false, Input: not null, Value: not null })
|
||||||
{
|
{
|
||||||
OnCalculatePressed();
|
OnCalculatePressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
_data.Operation = operation;
|
_data.Operation = operation;
|
||||||
|
|
||||||
|
if (_data.Input != null)
|
||||||
|
{
|
||||||
|
_data.Value = double.Parse(_data.Input);
|
||||||
|
}
|
||||||
|
|
||||||
|
_data.Input = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOperandPressed(char obj)
|
private void OnOperandPressed(char obj)
|
||||||
{
|
{
|
||||||
|
if (_data.Caculated)
|
||||||
if (_data is { Operands.Count: 1, Operation: not null })
|
|
||||||
{
|
{
|
||||||
_data.Operands.Push("0");
|
Clear(full: false);
|
||||||
}
|
|
||||||
else if (_data is { Caculated: true })
|
|
||||||
{
|
|
||||||
Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var operand = _data.Operands.Pop();
|
_data.Input = _inputService.TryInput(_data.Input + obj);
|
||||||
|
UpdateView(_data.Input);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateView(double input)
|
||||||
|
{
|
||||||
|
_view.UpdateView(input.ToString("0.#####"));
|
||||||
|
}
|
||||||
|
|
||||||
_data.Operands.Push(_inputService.TryInput(operand + obj));
|
private void UpdateView(string input)
|
||||||
_view.UpdateView(_data.Operands.Peek());
|
{
|
||||||
|
_view.UpdateView(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
1318
Form1.Designer.cs
generated
1318
Form1.Designer.cs
generated
File diff suppressed because it is too large
Load diff
121
Form1.cs
121
Form1.cs
|
|
@ -1,4 +1,5 @@
|
||||||
using calculator.View;
|
using calculator.Common;
|
||||||
|
using calculator.View;
|
||||||
|
|
||||||
namespace calculator
|
namespace calculator
|
||||||
{
|
{
|
||||||
|
|
@ -10,9 +11,9 @@ namespace calculator
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<char>? OperandPressed;
|
public event Action<char>? OperandPressed;
|
||||||
public event Action<string>? OperatorPressed;
|
public event Action<Operation>? OperatorPressed;
|
||||||
public event Action<string>? SingleOperatorPressed;
|
public event Action<Operation>? SingleOperatorPressed;
|
||||||
public event Action? ClearPressed;
|
public event Action<bool>? ClearPressed;
|
||||||
public event Action? CalculatePressed;
|
public event Action? CalculatePressed;
|
||||||
|
|
||||||
public void UpdateView(string input)
|
public void UpdateView(string input)
|
||||||
|
|
@ -22,7 +23,12 @@ namespace calculator
|
||||||
|
|
||||||
private void OnCEButtonClick(object sender, EventArgs e)
|
private void OnCEButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ClearPressed?.Invoke();
|
ClearPressed?.Invoke(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ClearPressed?.Invoke(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnZeroButtonClick(object sender, EventArgs e)
|
private void OnZeroButtonClick(object sender, EventArgs e)
|
||||||
|
|
@ -82,42 +88,77 @@ namespace calculator
|
||||||
|
|
||||||
private void OnNegativeButtonClick(object sender, EventArgs e)
|
private void OnNegativeButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SingleOperatorPressed?.Invoke("-1");
|
SingleOperatorPressed?.Invoke(Operation.Neg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlusButtonClick(object sender, EventArgs e)
|
private void OnPlusButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OperatorPressed?.Invoke("+");
|
OperatorPressed?.Invoke(Operation.Add);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMinusButtonClick(object sender, EventArgs e)
|
private void OnMinusButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OperatorPressed?.Invoke("-");
|
OperatorPressed?.Invoke(Operation.Sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMultButtonClick(object sender, EventArgs e)
|
private void OnMultButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OperatorPressed?.Invoke("*");
|
OperatorPressed?.Invoke(Operation.Mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDivideButtonClick(object sender, EventArgs e)
|
private void OnDivideButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
OperatorPressed?.Invoke("/");
|
OperatorPressed?.Invoke(Operation.Div);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSqrtButtonClick(object sender, EventArgs e)
|
private void OnSqrtButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SingleOperatorPressed?.Invoke("√");
|
SingleOperatorPressed?.Invoke(Operation.Sqrt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPercentButtonClick(object sender, EventArgs e)
|
private void OnPercentButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SingleOperatorPressed?.Invoke("%");
|
SingleOperatorPressed?.Invoke(Operation.Percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInverseButtonClick(object sender, EventArgs e)
|
private void OnInverseButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SingleOperatorPressed?.Invoke("1/");
|
SingleOperatorPressed?.Invoke(Operation.OneDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSinhButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Sinh);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSinButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Sin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCoshButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Cosh);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCosButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Cos);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTanhButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Tanh);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTanButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Tan);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSqrtYButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.SqrtY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEqualButtonClick(object sender, EventArgs e)
|
private void OnEqualButtonClick(object sender, EventArgs e)
|
||||||
|
|
@ -125,9 +166,59 @@ namespace calculator
|
||||||
CalculatePressed?.Invoke();
|
CalculatePressed?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button39_Click(object sender, EventArgs e)
|
private void OnFactorialButtonClick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Factorial);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnModButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCubeRootButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.CubeRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSquareButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Square);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPowYButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.PowY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCubeButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Cube);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLogButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Log);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnInvButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLnButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Ln);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnExpButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPiButtonClick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SingleOperatorPressed?.Invoke(Operation.Pi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
49
Form1.resx
49
Form1.resx
|
|
@ -123,61 +123,61 @@
|
||||||
<metadata name="button49.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="button49.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button50.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Log_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button51.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Mod_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button52.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Exp_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button53.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="button53.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button44.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="CubeRoot_Button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button45.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Cube_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button46.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Tan_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button47.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Tanh_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button48.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Pi_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button39.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="SqrtY_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button40.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="PowY_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button41.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Cos_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button42.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Cosh_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button43.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="dms_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button34.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Factorial_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button35.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Square_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button36.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Sin_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button37.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Sinh_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button38.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Int_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button23.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="button23.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
|
@ -186,10 +186,10 @@
|
||||||
<metadata name="button30.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="button30.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button31.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Ln_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button32.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="Inv_button.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="button33.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="button33.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
|
@ -291,6 +291,15 @@
|
||||||
<metadata name="radioButton1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="radioButton1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="radioButton3.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="radioButton2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="radioButton1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>True</value>
|
||||||
|
</metadata>
|
||||||
<metadata name="linkLabel1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="linkLabel1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
namespace calculator.Model;
|
using calculator.Common;
|
||||||
|
|
||||||
|
namespace calculator.Model;
|
||||||
|
|
||||||
public class CaculatorData
|
public class CaculatorData
|
||||||
{
|
{
|
||||||
public Stack<string> Operands { get; set; } = new();
|
public string? Input { get; set; }
|
||||||
public string? Operation { get; set; }
|
public double? Value { get; set; }
|
||||||
public string? SingleOperation { get; set; }
|
public Operation? Operation { get; set; }
|
||||||
public bool Caculated { get; set; }
|
public bool Caculated { get; set; }
|
||||||
public string? LastOperand { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,57 +1,90 @@
|
||||||
using System.Globalization;
|
using calculator.Common;
|
||||||
|
|
||||||
namespace calculator.Services
|
namespace calculator.Services
|
||||||
{
|
{
|
||||||
internal class Caculyator : ICaculator
|
internal class Caculyator : ICaculator
|
||||||
{
|
{
|
||||||
public string Calculate(string n, string m, string operation)
|
public double Calculate(Operation operation, double a, double? b = null)
|
||||||
{
|
{
|
||||||
if (double.TryParse(n, out var numberone) == false)
|
return b is null
|
||||||
return string.Empty;
|
? ApplyOperator(operation, a)
|
||||||
if (double.TryParse(m, out var numbertwo) == false)
|
: ApplyOperator(operation, a, b.Value);
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
return ApplyOperator(operation, numberone, numbertwo).ToString("0.#####");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SingleOperation(string operand, string operation)
|
private static double ApplyOperator(Operation token, double a, double b)
|
||||||
{
|
|
||||||
if (double.TryParse(operand, out var numberone) == false)
|
|
||||||
return string.Empty;
|
|
||||||
return ApplyOperator(operation, numberone).ToString("0.#####");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double ApplyOperator(string token, double operand1, double operand2)
|
|
||||||
{
|
{
|
||||||
switch (token)
|
switch (token)
|
||||||
{
|
{
|
||||||
case "+":
|
case Operation.Add:
|
||||||
return operand1 + operand2;
|
return a + b;
|
||||||
case "-":
|
case Operation.Sub:
|
||||||
return operand1 - operand2;
|
return a - b;
|
||||||
case "*":
|
case Operation.Mul:
|
||||||
return operand1 * operand2;
|
return a * b;
|
||||||
case "/":
|
case Operation.Div:
|
||||||
return operand1 / operand2;
|
return a / b;
|
||||||
case "^":
|
case Operation.Pow:
|
||||||
return Math.Pow(operand1, operand2);
|
return Math.Pow(a, b);
|
||||||
|
case Operation.SqrtY:
|
||||||
|
return Math.Pow(a, 1 / b);
|
||||||
|
case Operation.PowY:
|
||||||
|
return Math.Pow(a, b);
|
||||||
|
case Operation.Mod:
|
||||||
|
return a % b;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException($"Invalid operator: {token}");
|
throw new ArgumentException($"Invalid operator: {token}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double ApplyOperator(string token, double operand1)
|
private static double Factorial(double n)
|
||||||
|
{
|
||||||
|
if (n == 0)
|
||||||
|
return 1;
|
||||||
|
return n * Factorial(n - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double ApplyOperator(Operation token, double a)
|
||||||
{
|
{
|
||||||
switch (token)
|
switch (token)
|
||||||
{
|
{
|
||||||
case "1/":
|
case Operation.OneDiv:
|
||||||
return 1 / operand1;
|
return 1 / a;
|
||||||
case "√":
|
case Operation.Sqrt:
|
||||||
return Math.Sqrt(operand1);
|
return Math.Sqrt(a);
|
||||||
case "%":
|
case Operation.Percent:
|
||||||
return operand1 / 100;
|
return a / 100;
|
||||||
case "-1":
|
case Operation.Neg:
|
||||||
return operand1 * -1;
|
return a * -1;
|
||||||
|
case Operation.Sinh:
|
||||||
|
return Math.Sinh(a);
|
||||||
|
case Operation.Sin:
|
||||||
|
return Math.Sin(a);
|
||||||
|
case Operation.Cosh:
|
||||||
|
return Math.Cosh(a);
|
||||||
|
case Operation.Cos:
|
||||||
|
return Math.Cos(a);
|
||||||
|
case Operation.Tanh:
|
||||||
|
return Math.Tanh(a);
|
||||||
|
case Operation.Tan:
|
||||||
|
return Math.Tan(a);
|
||||||
|
case Operation.Factorial:
|
||||||
|
return Factorial(a);
|
||||||
|
case Operation.Square:
|
||||||
|
return Math.Pow(a, 2);
|
||||||
|
case Operation.Cube:
|
||||||
|
return Math.Pow(a, 3);
|
||||||
|
case Operation.CubeRoot:
|
||||||
|
return Math.Pow(a, 1 / 3);
|
||||||
|
case Operation.Log:
|
||||||
|
return Math.Log10(a);
|
||||||
|
case Operation.Ln:
|
||||||
|
return Math.Log(a);
|
||||||
|
case Operation.Exp:
|
||||||
|
return Math.Exp(a);
|
||||||
|
case Operation.Inv:
|
||||||
|
return 1 / a;
|
||||||
|
case Operation.Pi:
|
||||||
|
return Math.PI;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException($"Invalid operator: {token}");
|
throw new ArgumentException($"Invalid operator: {token}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
namespace calculator.Services;
|
using calculator.Common;
|
||||||
|
|
||||||
|
namespace calculator.Services;
|
||||||
|
|
||||||
public interface ICaculator
|
public interface ICaculator
|
||||||
{
|
{
|
||||||
string Calculate(string op1, string op2, string operation);
|
double Calculate(Operation operation, double a, double? b = null);
|
||||||
string SingleOperation(string operand, string operation);
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
namespace calculator.View;
|
using calculator.Common;
|
||||||
|
|
||||||
|
namespace calculator.View;
|
||||||
|
|
||||||
public interface ICaculatorView
|
public interface ICaculatorView
|
||||||
{
|
{
|
||||||
public event Action<char> OperandPressed;
|
public event Action<char> OperandPressed;
|
||||||
public event Action<string> OperatorPressed;
|
public event Action<Operation> OperatorPressed;
|
||||||
public event Action<string> SingleOperatorPressed;
|
public event Action<bool> ClearPressed;
|
||||||
public event Action ClearPressed;
|
|
||||||
public event Action CalculatePressed;
|
public event Action CalculatePressed;
|
||||||
|
public event Action<Operation> SingleOperatorPressed;
|
||||||
public void UpdateView(string input);
|
public void UpdateView(string input);
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue