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

TaskPerformance Muni

This document contains code for a basic calculator application. It defines a Windows form with text boxes for inputting two numbers and selecting an operator. When the compute button is clicked, it parses the user input and performs the calculation using methods in a BasicComputation class. The result is displayed in an output text box. It also initializes the form fields and operator dropdown on load.

Uploaded by

Saiden Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

TaskPerformance Muni

This document contains code for a basic calculator application. It defines a Windows form with text boxes for inputting two numbers and selecting an operator. When the compute button is clicked, it parses the user input and performs the calculation using methods in a BasicComputation class. The result is displayed in an output text box. It also initializes the form fields and operator dropdown on load.

Uploaded by

Saiden Abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

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

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

private void btnCompute_Click(object sender, EventArgs e)


{

float num1 = float.Parse(txtNum1.Text);


float num2 = float.Parse(txtNum2.Text);
if (!float.TryParse(txtNum1.Text, out num1))
{
MessageBox.Show("First Input Invalid!!");
return;
}

if (!float.TryParse(txtNum2.Text, out num2))


{
MessageBox.Show("First Input Invalid!!");
return;
}

string oper = cbOperator.Text;

switch (oper)
{
case "+":
Calculate.BasicComputation add = new Calculate.BasicComputation();
txtOutput.Text = "Total" + Environment.NewLine +
Convert.ToString(add.Addition(Convert.ToInt16(txtNum1.Text), Convert.ToInt16(txtNum2.Text)));
break;
case "-":
Calculate.BasicComputation subtract = new Calculate.BasicComputation();
txtOutput.Text = "Total" + Environment.NewLine +
Convert.ToString(subtract.Subtraction(Convert.ToInt16(txtNum1.Text), Convert.ToInt16(txtNum2.Text)));
break;
case "*":
Calculate.BasicComputation multiply = new Calculate.BasicComputation();
txtOutput.Text = "Total" + Environment.NewLine +
Convert.ToString(multiply.Multiply(Convert.ToInt16(txtNum1.Text), Convert.ToInt16(txtNum2.Text)));
break;
case "/":
if (num1 == 0 || num2 == 0)
{
MessageBox.Show("Division by ZERO");
}
else
{
Calculate.BasicComputation divide = new Calculate.BasicComputation();
txtOutput.Text = "Total" + Environment.NewLine +
Convert.ToString(divide.Division(Convert.ToInt16(txtNum1.Text), Convert.ToInt16(txtNum2.Text)));
}
break;
default:
MessageBox.Show("Operator is invalid");
break;

private void Form1_Load(object sender, EventArgs e)


{
string[] operators = new string[]
{
"+",
"-",
"/",
"*",
};
for (int x = 0; x < 4; x++)
{
cbOperator.Items.Add(operators[x].ToString());
}

txtNum1.Text = "0";
txtNum2.Text = "0";
txtOutput.Text = "Total: \n \r" + Environment.NewLine + "\r \n 000000";

private void txtOutput_TextChanged(object sender, EventArgs e)


{

}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Calculate {
public class BasicComputation
{
public float Addition(float number1, float number2)
{
float result = number1 + number2;
return result;
}
public float Subtraction(float number1, float number2)
{
float result = number1 - number2;
return result;
}
public float Division(float number1, float number2)
{
float result = number1 / number2;
return result;
}
public float Multiply(float number1, float number2)
{
float result = number1 * number2;
return result;
}

}
}
}

You might also like