0% found this document useful (0 votes)
58 views

Muhammad Bilal (01-133142-074) : Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document describes a C# Windows Forms calculator application. It contains a Form1 class with button click event handlers that add numbers and operators to a textBox. A calculator class contains static methods to add, subtract, multiply, and divide numbers in the textBox and clear its contents. When the equals button is clicked, the calculator class splits the textBox text on operators, converts parts to integers, performs the operation, and updates the textBox.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Muhammad Bilal (01-133142-074) : Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document describes a C# Windows Forms calculator application. It contains a Form1 class with button click event handlers that add numbers and operators to a textBox. A calculator class contains static methods to add, subtract, multiply, and divide numbers in the textBox and clear its contents. When the equals button is clicked, the calculator class splits the textBox text on operators, converts parts to integers, performs the operation, and updates the textBox.

Uploaded by

Muhammad Bilal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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