Добавлены операци:
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
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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue