You are on page 1of 10

Muhammad Bilal (01-133142-074)

using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace Calculator

public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
textBox1.Text = "Enter Numbers";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "1";
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "2";
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "3";
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "4";
}

Muhammad Bilal (01-133142-074)

private void button5_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "5";

private void button6_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "6";

private void button7_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "7";

private void button8_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "8";

private void button9_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "9";

private void button11_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}

Muhammad Bilal (01-133142-074)

textBox1.Text += "0";

private void buttonAdd_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "+";

private void buttonSub_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "-";

private void buttonMul_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "*";

private void buttonDiv_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "/";

private void buttonClear_Click(object sender, EventArgs e)


{
textBox1.Text = "";
}
private void buttonEqual_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains('+'))
{
var nums = textBox1.Text.Split('+');
textBox1.Text += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) + Convert.ToInt32(nums[1]));
}
else if(textBox1.Text.Contains('-'))
{

Muhammad Bilal (01-133142-074)


var nums = textBox1.Text.Split('-');
textBox1.Text += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) - Convert.ToInt32(nums[1]));

}
}

}
else if (textBox1.Text.Contains('*'))
{
var nums = textBox1.Text.Split('*');
textBox1.Text += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) * Convert.ToInt32(nums[1]));
}
else if (textBox1.Text.Contains('/'))
{
var nums = textBox1.Text.Split('/');
textBox1.Text += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0])
/ Convert.ToInt32(nums[1]));
}

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Calculator
{
public class calculator
{
public static string add(string s)
{
if (s == "enter number")
{
s = "";
}

Muhammad Bilal (01-133142-074)


s += "+";
return s;
}

public static string sub(string s)


{
if (s == "enter number")
{
s = "";
}
s += "-";
return s;
}

public static string mul(string s)


{
if (s == "enter number")
{
s = "";
}
s += "*";
return s;

public static string div(string s)


{
if (s == "enter number")
{
s = "";
}
s += "/";
return s;
}

}
}
}

public static string equals(string s)


{
if (s == "enter number")
{
s = "";
}
s += "=";
return s;
}
public static string clear(string s)
{
if (s == "enter number")
{
s = "";
}
s = "";
return s;
}

Muhammad Bilal (01-133142-074)


}

using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = "Enter Numbers";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "1";

private void button2_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
}

textBox1.Text += "2";

private void button3_Click(object sender, EventArgs e)


{
if (textBox1.Text == "Enter Numbers")
{

Muhammad Bilal (01-133142-074)

textBox1.Text = "";

textBox1.Text += "3";
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "4";
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "5";
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "6";
}
private void button7_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "7";
}
private void button8_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "8";
}
private void button9_Click(object sender, EventArgs e)
{

Muhammad Bilal (01-133142-074)


if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "9";
}
private void button11_Click(object sender, EventArgs e)
{
if (textBox1.Text == "Enter Numbers")
{
textBox1.Text = "";
}
textBox1.Text += "0";
}
private void buttonAdd_Click(object sender, EventArgs e)
{
textBox1.Text = calculator.add(textBox1.Text);
}
private void buttonSub_Click(object sender, EventArgs e)
{
textBox1.Text = calculator.sub(textBox1.Text);
}
private void buttonMul_Click(object sender, EventArgs e)
{
textBox1.Text = calculator.mul(textBox1.Text);
}
private void buttonDiv_Click(object sender, EventArgs e)
{
textBox1.Text = calculator.div(textBox1.Text);
}
private void buttonClear_Click(object sender, EventArgs e)
{
calculator.clear(textBox1.Text);
}
private void buttonEqual_Click(object sender, EventArgs e)
{
textBox1.Text = calculator.equals(textBox1.Text);

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

Muhammad Bilal (01-133142-074)

namespace Calculator
{
public class calculator
{
public static string add(string s)
{
if (s == "enter number")
{
s = "";
}
s += "+";
return s;
}

public static string sub(string s)


{
if (s == "enter number")
{
s = "";
}
s += "-";
return s;
}

public static string mul(string s)


{
if (s == "enter number")
{
s = "";
}
s += "*";
return s;

public static string div(string s)


{
if (s == "enter number")
{
s = "";
}
s += "/";
return s;
}

public static string clear(string s)


{
if (s == "enter number")
{
s = "";
}
s = "";
return s;
}

Muhammad Bilal (01-133142-074)

public static string equals(string s)


if (s.Contains('+'))
{
var nums = s.Split('+');
s += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) + Convert.ToInt32(nums[1]));
}
else if(s.Contains('-'))
{
var nums = s.Split('-');
s += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) - Convert.ToInt32(nums[1]));
}
else if (s.Contains('*'))
{
var nums = s.Split('*');
s += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0]) * Convert.ToInt32(nums[1]));
}
else if (s.Contains('/'))
{
var nums = s.Split('/');
s += System.Environment.NewLine + System.Environment.NewLine +
(Convert.ToInt32(nums[0])
/ Convert.ToInt32(nums[1]));
}
return s;
}

}
}

You might also like