Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Calculator/Calculator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Calculator", "Calculator\Calculator.csproj", "{1C4C74BA-A10B-4E03-BD5E-502C0722D6C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalculatorTests", "CalculatorTests\CalculatorTests.csproj", "{98AFD684-BA58-4412-98AC-3DE873088559}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1C4C74BA-A10B-4E03-BD5E-502C0722D6C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1C4C74BA-A10B-4E03-BD5E-502C0722D6C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1C4C74BA-A10B-4E03-BD5E-502C0722D6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1C4C74BA-A10B-4E03-BD5E-502C0722D6C7}.Release|Any CPU.Build.0 = Release|Any CPU
{98AFD684-BA58-4412-98AC-3DE873088559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98AFD684-BA58-4412-98AC-3DE873088559}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98AFD684-BA58-4412-98AC-3DE873088559}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98AFD684-BA58-4412-98AC-3DE873088559}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {87D0854A-0000-4021-B618-51922D5D7F45}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions Calculator/Calculator/Calculator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
540 changes: 540 additions & 0 deletions Calculator/Calculator/CalculatorForm.Designer.cs

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions Calculator/Calculator/CalculatorForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
namespace Calculator;

public partial class CalculatorForm : Form
{
public string FirstOperand { get; private set; } = "";
public string SecondOperand { get; private set; } = "";
public char CurrentOperator { get; private set; } = '\0';

public CalculatorForm()
{
InitializeComponent();
}

public void OperandClick(object sender, EventArgs e)
{
if (CurrentOperator != '\0')
{
SecondOperand += (sender as Button)!.Text;
}
else
{
FirstOperand += (sender as Button)!.Text;
}
}

public void OperatorClick(object sender, EventArgs e)
{
if (FirstOperand == "")
{
return;
}
if (SecondOperand == "")
{
if ((sender as Button)!.Text == "√")
{
FirstOperand = Math.Sqrt(double.Parse(FirstOperand)).ToString("G29");
return;
}
CurrentOperator = Convert.ToChar((sender as Button)!.Text);
}
else
{
decimal decimalFirstOperand = (decimal)double.Parse(FirstOperand);
decimal decimalSecondOperand = (decimal)double.Parse(SecondOperand);
if ((sender as Button)!.Text == "√")
{
SecondOperand = Math.Sqrt((double)decimalSecondOperand).ToString("G29");
return;
}
switch (CurrentOperator)
{
case '+':
{
FirstOperand = (decimalFirstOperand + decimalSecondOperand).ToString("G29");
break;
}
case '-':
{
FirstOperand = (decimalFirstOperand - decimalSecondOperand).ToString("G29");
break;
}
case '✕':
{
FirstOperand = (decimalFirstOperand * decimalSecondOperand).ToString("G29");
break;
}
case '÷':
{
FirstOperand = (decimalFirstOperand / decimalSecondOperand).ToString("G29");
break;
}
}
CurrentOperator = (sender as Button)!.Text == "=" ? '\0' : Convert.ToChar((sender as Button)!.Text);
SecondOperand = "";
}
}

public void ButtonBackspaceClick(object sender, EventArgs e)
{
if (SecondOperand != "")
{
SecondOperand = SecondOperand.Remove(SecondOperand.Length - 1);
}
else if (CurrentOperator != '\0')
{
CurrentOperator = '\0';
}
else if (FirstOperand != "")
{
FirstOperand = FirstOperand.Remove(FirstOperand.Length - 1);
}
}

public void ButtonNegationClick(object sender, EventArgs e)
{
if (SecondOperand != "")
{
if (SecondOperand[0] == '-')
{
SecondOperand = SecondOperand.Substring(1);
return;
}
SecondOperand = "-" + SecondOperand;
}
else if (FirstOperand != "")
{
if (FirstOperand[0] == '-')
{
FirstOperand = FirstOperand.Substring(1);
return;
}
FirstOperand = "-" + FirstOperand;
}
}

public void ButtonDecimalPointClick(object sender, EventArgs e)
{
if (SecondOperand != "")
{
SecondOperand += SecondOperand.Contains(',') ? "" : ',';
}
else if (FirstOperand != "")
{
FirstOperand += FirstOperand.Contains(',') ? "" : ',';
}
}

public void ButtonClearClick(object sender, EventArgs e)
{
SecondOperand = "";
CurrentOperator = '\0';
FirstOperand = "";
}
}
60 changes: 60 additions & 0 deletions Calculator/Calculator/CalculatorForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
15 changes: 15 additions & 0 deletions Calculator/Calculator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Calculator
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new CalculatorForm());
}
}
}
Loading