基本信息
源码名称:C# 计算器(实现了加、减、乘、除、取余、sqrt等算法)
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2019-06-03
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Form1 : Form
{
string str, opp, opp1;
double num1, num2, result;
public Form1()
{
InitializeComponent();
}
private void number(object sender, EventArgs e)
{
Button b = (Button)(sender);
str = b.Text;
if (txtOutput.Text == "0")
{
txtOutput.Text = str;
}
else
txtOutput.Text = txtOutput.Text str;
}
private void operator1(object sender, EventArgs e)
{
Button b = (Button)(sender);
if (b.Text == " ")
{
num1 = double.Parse(txtOutput.Text);
txtOutput.Text = "";
opp = " ";
opp1 = "";
}
else if (b.Text == "-")
{
num1 = double.Parse(txtOutput.Text);
txtOutput.Text = "";
opp = "-";
opp1 = "";
}
else if (b.Text == "*")
{
num1 = double.Parse(txtOutput.Text);
txtOutput.Text = "";
opp = "*";
opp1 = "";
}
else if (b.Text == "/")
{
num1 = double.Parse(txtOutput.Text);
txtOutput.Text = "";
opp = "/";
opp1 = "";
}
else if (b.Text == "=")
{
if (opp1 != "=")
{
num2 = double.Parse(txtOutput.Text);
}
if (opp == " ")
{
num1 = num1 num2;
txtOutput.Text = "" num1.ToString();
}
else if (opp == "-")
{
num1 = num1 - num2;
txtOutput.Text = "" num1.ToString();
}
else if (opp == "*")
{
num1 = num1 * num2;
txtOutput.Text = "" num1.ToString();
}
else if (opp == "/")
{
if (num2 == 0)
{
txtOutput.Text = "除数不能为零";
}
else
{
num1 = num1 / num2;
txtOutput.Text = "" num1.ToString();
}
}
opp1 = "=";
}
}
private void operator2(object sender, EventArgs e)
{
Button b = (Button)(sender);
if (b.Text == ".")
{
str = txtOutput.Text;
int index = str.IndexOf(".");
if (index == -1)
{
txtOutput.Text = str ".";
}
}
else if (b.Text == "退格<--")
{
if (txtOutput.Text != "")
{
str = txtOutput.Text;
str = str.Substring(0, str.Length - 1);
txtOutput.Text = str;
}
}
else if (b.Text == "CE")
{
txtOutput.Text = "0";
}
else if (b.Text == "C")
{
result = num1 = num2 = 0;
str = null;
opp = null;
txtOutput.Text = "0";
}
else if (b.Text == "sqrt")
{
num1 = double.Parse(txtOutput.Text);
result = Math.Sqrt(num1);
txtOutput.Text = result.ToString();
}
else if (b.Text == "1/x")
{
num1 = double.Parse(txtOutput.Text);
result = 1 / num1;
txtOutput.Text = result.ToString();
}
else if (b.Text == "%")
{
num1 = double.Parse(txtOutput.Text);
result = num1 / 100;
txtOutput.Text = result.ToString();
}
opp1 = "";
}
}
}