Windows Calculator Complete…

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;

namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

double textboxnumber;
long first;
long second;
private void button15_Click(object sender, EventArgs e)
{
{
double a1, b1, c1;
string s = null;
string t = null;
char[] x = textBox1.Text.ToCharArray();
if (textBox1.Text == null)
{
throw new ArgumentNullException();
}
try
{
for (int a = 0; a < x.Length; a++)
{
if (x[a] == ‘+’)
{
for (int b = 0; b < a; b++)
{

s += x[b].ToString();

}
for (int g = a; g < x.Length; g++)
{
t += x[g].ToString();

}

a1 = double.Parse(s);
b1 = double.Parse(t);
c1 = a1 + b1;
textBox1.Text = c1.ToString();
}
}
for (int a = 0; a < x.Length; a++)
{
if (x[a] == ‘-‘)
{
for (int b = 0; b < a; b++)
{

s += x[b].ToString();

}
for (int g = a + 1; g < x.Length; g++)
{
t += x[g].ToString();

}

a1 = double.Parse(s);
b1 = double.Parse(t);
c1 = a1 – b1;
textBox1.Text = c1.ToString();
}
}
for (int a = 0; a < x.Length; a++)
{
if (x[a] == ‘*’)
{
for (int b = 0; b < a; b++)
{

s += x[b].ToString();

}
for (int g = a + 1; g < x.Length; g++)
{
t += x[g].ToString();

}

a1 = double.Parse(s);
b1 = double.Parse(t);
c1 = a1 * b1;
textBox1.Text = c1.ToString();
}
}
for (int a = 0; a < x.Length; a++)
{
if (x[a] == ‘/’)
{
for (int b = 0; b < a; b++)
{

s += x[b].ToString();

}
for (int g = a + 1; g < x.Length; g++)
{
t += x[g].ToString();

}

a1 = double.Parse(s);
b1 = double.Parse(t);
c1 = a1 / b1;
textBox1.Text = c1.ToString();
}
}
second = (long)(textboxnumber);
label1.Text = “”;
if (difference == 1)
{
textBox1.Text = Permutation(first, second).ToString();
}
else if(difference == 2)
textBox1.Text = Combinatorial(first, second).ToString();
}
catch
{

textBox1.Text = “Enter a correct value”;

}
}
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += “1”;
}

private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += “2”;
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += “3”;
}

private void button4_Click(object sender, EventArgs e)
{
textBox1.Text += “4”;
}

private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += “5”;
}

private void button6_Click(object sender, EventArgs e)
{
textBox1.Text += “6”;
}

private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += “7”;
}

private void button8_Click(object sender, EventArgs e)
{
textBox1.Text += “8”;
}

private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += “9”;
}

private void button10_Click(object sender, EventArgs e)
{
textBox1.Text += “0”;
}

private void button11_Click(object sender, EventArgs e)
{
textBox1.Text += “+”;
}

private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += “*”;
}

private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += “-“;
}

private void button14_Click(object sender, EventArgs e)
{
textBox1.Text += “/”;
}

private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = “”;
}

private void Form1_MouseClick(object sender, MouseEventArgs e)
{

}

private void button17_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = Math.Sin(textboxnumber).ToString();
}
catch
{
textBox1.Text = “Enter the correct value”;

}

}

private void button18_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = Math.Cos(textboxnumber).ToString();
}
catch
{
textBox1.Text = “Enter the correct value”;
}

}

private void button19_Click(object sender, EventArgs e)
{

{
textBox1.Text = Math.Tan(textboxnumber).ToString();
}

}

private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
textboxnumber = double.Parse(textBox1.Text);

}
catch
{

}

}

public  long Factorial(long number)
{
if (number <= 1) return 1;
return  number * Factorial(number – 1);
}
public long Permutation(long n, long r)
{
if (r == 0) return 0;
if (n == 0) return 0;
if ((r >= 0) && (r <= n))
return Factorial(n) / Factorial(n – r);
else return 0;
}
public long Combinatorial(long a, long b)
{
if (a <= 1) return 1;
return Factorial(a) / ((Factorial(b) * Factorial(a – b)));
}

long factor1;
private void button20_Click(object sender, EventArgs e)
{
long factor = 0;

factor = (long)(textboxnumber);

factor1 = Factorial(factor);
textBox1.Text = factor1.ToString();
//  textBox3.Text = exo.Permutation(factor, second).ToString();
//textBox4.Text = exo.Combinatorial(factor, second).ToString();
}
int difference = 0;
private void button21_Click(object sender, EventArgs e)
{

difference = 1;
first = (long)(textboxnumber);
label1.Text = “enter second number”;
textBox1.Clear();

}

private void button22_Click(object sender, EventArgs e)
{

difference = 2;
first = (long)(textboxnumber);
label1.Text = “enter second number”;
textBox1.Clear();

}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s