Design
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Scientific_Calculator1
{
public partial class frmcientificcalculator : Form
{
string operation;
Double firstnumber = 0;
Double secoundnumber = 0;
bool Operation_passed = false;
public frmcientificcalculator()
{
InitializeComponent();
}
private void standardToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Width = 433;
txtresult.Width = 389;
}
private void scientificToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Width = 853;
txtresult.Width = 790;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void frmcientificcalculator_Load(object sender, EventArgs e)
{
this.Width = 433;
txtresult.Width = 389;
}
private void Button_click(object sender, EventArgs e)
{
if (txtresult.Text == "0" || Operation_passed)
{
txtresult.Clear();
}
Operation_passed = false;
Button b = (Button)sender;
if (b.Text == ".")
{
if (!txtresult.Text.Contains("."))
{
txtresult.Text = txtresult.Text + b.Text;
}
}
else
{
txtresult.Text = txtresult.Text + b.Text;
}
}
private void btnclear_Click(object sender, EventArgs e)
{
txtresult.Text = "0";
lblshow.Text = "";
}
private void OPeration_click(object sender, EventArgs e)
{
if (firstnumber != 0)
{
Button b = (Button)sender;
btnequal.PerformClick();
operation = b.Text;
Operation_passed = true;
lblshow.Text = txtresult.Text + b.Text;
}
else
{
Button b = (Button)sender;
operation = b.Text;
firstnumber = Convert.ToDouble(txtresult.Text);
Operation_passed = true;
lblshow.Text = txtresult.Text + b.Text;
}
}
private void btnequal_Click(object sender, EventArgs e)
{
secoundnumber = Convert.ToDouble(txtresult.Text);
lblshow.Text = "";
if (operation == "+")
{
txtresult.Text = Convert.ToString(firstnumber + secoundnumber);
}
if (operation == "-")
{
txtresult.Text = Convert.ToString(firstnumber - secoundnumber);
}
if (operation == "*")
{
txtresult.Text = Convert.ToString(firstnumber * secoundnumber);
}
if (operation == "/")
{
txtresult.Text = Convert.ToString(firstnumber / secoundnumber);
}
if(operation=="MOD")
{
txtresult.Text=Convert.ToString(firstnumber % secoundnumber);
}
firstnumber = Convert.ToDouble(txtresult.Text);
lblshow.Text = "";
}
private void btnc_Click(object sender, EventArgs e)
{
txtresult.Text = "0";
lblshow.Text = "";
}
private void btnsquare_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = num * num;
lblshow.Text = "sqre" +"("+num+")";
txtresult.Text = Convert.ToString(a);
}
private void btnpi_Click(object sender, EventArgs e)
{
txtresult.Text = "3.141592653589976323";
}
private void btnqube_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = num * num*num;
lblshow.Text = "cube" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btnsqrt_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Sqrt(num);
lblshow.Text = "sqrt" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btndividvalue_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = 1/num;
lblshow.Text = "1" + "/" + num;
txtresult.Text = Convert.ToString(a);
}
private void btnlog_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
txtresult.Text = "log " + "(" + txtresult.Text + ")";
a = Math.Log10(num);
lblshow.Text = "LOG10" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btnlnx_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Log(num);
lblshow.Text = "LOG" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btnsin_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Sin(num);
lblshow.Text = "SIN" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btncos_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Cos(num);
lblshow.Text = "COS" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btntan_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Tan(num);
lblshow.Text = "TAN" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btnsinh_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Sinh(num);
lblshow.Text = "Sinh" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btncosh_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Cosh(num);
lblshow.Text = "Cosh" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btntanh_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = Math.Tanh(num);
lblshow.Text = "Tanh" + "(" + num + ")";
txtresult.Text = Convert.ToString(a);
}
private void btnbinary_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt16(txtresult.Text);
txtresult.Text = Convert.ToString(a, 2);
}
private void btnpersentage_Click(object sender, EventArgs e)
{
double a, num;
num = Convert.ToDouble(txtresult.Text);
a = num / 100;
lblshow.Text = num + "%";
txtresult.Text = Convert.ToString(a);
}
private void btndecimal1_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt16(txtresult.Text);
txtresult.Text = Convert.ToString(a, 8);
}
private void btnhexadecimal_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt16(txtresult.Text);
txtresult.Text = Convert.ToString(a, 16);
}
private void btnoctal_Click(object sender, EventArgs e)
{
int a;
a = Convert.ToInt16(txtresult.Text);
txtresult.Text = Convert.ToString(a, 10);
}
}
}
No comments:
Post a Comment