Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM , Design a calculator for Windows C#.NET
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace calc
{
public partial class Form1 : Form
{
double op1, op2, ans;
string str;
int len,oprator;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
txtDisplay.Text = "0";
}
private void btnOne_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text=="+" || txtDisplay.Text=="-" || txtDisplay.Text=="*" || txtDisplay.Text=="/" || txtDisplay.Text=="%")
txtDisplay.Text = "1";
else
txtDisplay.Text = txtDisplay.Text + "1";
}
private void btnTwo_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "2";
else
txtDisplay.Text = txtDisplay.Text + "2";
}
private void btnThree_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "3";
else
txtDisplay.Text = txtDisplay.Text + "3";
}
private void btnFour_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "4";
else
txtDisplay.Text = txtDisplay.Text + "4";
}
private void btnFive_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "5";
else
txtDisplay.Text = txtDisplay.Text + "5";
}
private void btnSix_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "6";
else
txtDisplay.Text = txtDisplay.Text + "6";
}
private void btnSeven_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "7";
else
txtDisplay.Text = txtDisplay.Text + "7";
}
private void btnEight_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "8";
else
txtDisplay.Text = txtDisplay.Text + "8";
}
private void btnNine_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "9";
else
txtDisplay.Text = txtDisplay.Text + "9";
}
private void btnZero_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0";
else
txtDisplay.Text = txtDisplay.Text + "0";
}
private void btnZeroZero_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0";
else
txtDisplay.Text = txtDisplay.Text + "00";
}
private void btnPoint_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0.";
else
txtDisplay.Text = txtDisplay.Text + ".";
}
private void btnAllClear_Click(object sender, EventArgs e)
{
txtDisplay.Text = "0";
}
private void btnDivide_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "/";
oprator = 1;
}
private void btnMultiply_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "*";
oprator = 2;
}
private void btnAddition_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "+";
oprator = 3;
}
private void btnSubtract_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "-";
oprator = 4;
}
private void btnPercent_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "%";
oprator = 5;
}
private void btnEqual_Click(object sender, EventArgs e)
{
op2 = Convert.ToDouble(txtDisplay.Text);
switch (oprator)
{
case 1:
ans = op1 / op2;
break;
case 2:
ans = op1 * op2;
break;
case 3:
ans = op1 + op2;
break;
case 4:
ans = op1 - op2;
break;
case 5:
ans = (op1 * 100) / op2;
break;
}
txtDisplay.Text = Convert.ToString(ans);
}
private void btnClear_Click(object sender, EventArgs e)
{
len = txtDisplay.Text.Length;
if (len != 0)
str = txtDisplay.Text.Remove(len - 1, 1);
else
txtDisplay.Text = "0";
txtDisplay.Text = str;
}
}
}
OUT PUT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace calc
{
public partial class Form1 : Form
{
double op1, op2, ans;
string str;
int len,oprator;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
txtDisplay.Text = "0";
}
private void btnOne_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text=="+" || txtDisplay.Text=="-" || txtDisplay.Text=="*" || txtDisplay.Text=="/" || txtDisplay.Text=="%")
txtDisplay.Text = "1";
else
txtDisplay.Text = txtDisplay.Text + "1";
}
private void btnTwo_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "2";
else
txtDisplay.Text = txtDisplay.Text + "2";
}
private void btnThree_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "3";
else
txtDisplay.Text = txtDisplay.Text + "3";
}
private void btnFour_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "4";
else
txtDisplay.Text = txtDisplay.Text + "4";
}
private void btnFive_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "5";
else
txtDisplay.Text = txtDisplay.Text + "5";
}
private void btnSix_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "6";
else
txtDisplay.Text = txtDisplay.Text + "6";
}
private void btnSeven_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "7";
else
txtDisplay.Text = txtDisplay.Text + "7";
}
private void btnEight_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "8";
else
txtDisplay.Text = txtDisplay.Text + "8";
}
private void btnNine_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "9";
else
txtDisplay.Text = txtDisplay.Text + "9";
}
private void btnZero_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0";
else
txtDisplay.Text = txtDisplay.Text + "0";
}
private void btnZeroZero_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0";
else
txtDisplay.Text = txtDisplay.Text + "00";
}
private void btnPoint_Click(object sender, EventArgs e)
{
if (txtDisplay.Text == "0" || txtDisplay.Text == "+" || txtDisplay.Text == "-" || txtDisplay.Text == "*" || txtDisplay.Text == "/" || txtDisplay.Text == "%")
txtDisplay.Text = "0.";
else
txtDisplay.Text = txtDisplay.Text + ".";
}
private void btnAllClear_Click(object sender, EventArgs e)
{
txtDisplay.Text = "0";
}
private void btnDivide_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "/";
oprator = 1;
}
private void btnMultiply_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "*";
oprator = 2;
}
private void btnAddition_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "+";
oprator = 3;
}
private void btnSubtract_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "-";
oprator = 4;
}
private void btnPercent_Click(object sender, EventArgs e)
{
op1 = Convert.ToDouble(txtDisplay.Text);
txtDisplay.Text = "%";
oprator = 5;
}
private void btnEqual_Click(object sender, EventArgs e)
{
op2 = Convert.ToDouble(txtDisplay.Text);
switch (oprator)
{
case 1:
ans = op1 / op2;
break;
case 2:
ans = op1 * op2;
break;
case 3:
ans = op1 + op2;
break;
case 4:
ans = op1 - op2;
break;
case 5:
ans = (op1 * 100) / op2;
break;
}
txtDisplay.Text = Convert.ToString(ans);
}
private void btnClear_Click(object sender, EventArgs e)
{
len = txtDisplay.Text.Length;
if (len != 0)
str = txtDisplay.Text.Remove(len - 1, 1);
else
txtDisplay.Text = "0";
txtDisplay.Text = str;
}
}
}
OUT PUT
Nagpur University MCA V Semester, C#.Net, Embedded System Programming, Nagpur University Practical MCA V SEM
No comments:
Post a Comment