0% found this document useful (0 votes)
22 views3 pages

TP Event Driven

This document contains code for a basic calculator application. It defines a BasicComputations class with methods for addition, subtraction, multiplication and division of float numbers. It also defines a BasicCalculator form class that allows users to enter two numbers and select an operation from a dropdown. When the compute button is clicked, it calls the corresponding method from BasicComputations class and displays the result.

Uploaded by

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

TP Event Driven

This document contains code for a basic calculator application. It defines a BasicComputations class with methods for addition, subtraction, multiplication and division of float numbers. It also defines a BasicCalculator form class that allows users to enter two numbers and select an operation from a dropdown. When the compute button is clicked, it calls the corresponding method from BasicComputations class and displays the result.

Uploaded by

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

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp6
{
public class BasicComputations
{
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 Multiplication(float number1, float number2)
{
float result = number1 * number2;
return result;
}
public float Division(float number1, float number2)
{
float result = number1 / number2;
return result;
}
}
}

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 WindowsFormsApp6
{
public partial class BasicCalculator : Form
{
public BasicCalculator()
{
InitializeComponent();
}

private void btnCompute_Click(object sender, EventArgs e)


{
float number1, number2;
if (!float.TryParse(textBox1.Text, out number1))
{
MessageBox.Show("First number invalid!");
return;
}
if (!float.TryParse(textBox2.Text, out number2))
{
MessageBox.Show("Second number invalid!");
return;
}

string oper = comboBox.Text;

switch (oper)
{

case "+":
WindowsFormsApp6.BasicComputations add = new
WindowsFormsApp6.BasicComputations();
textBox3.Text = "Total " + Environment.NewLine +
Convert.ToString(add.Addition(Convert.ToInt16(textBox1.Text),
Convert.ToInt16(textBox2.Text)));
break;

case "-":
WindowsFormsApp6.BasicComputations subtract = new
WindowsFormsApp6.BasicComputations();
textBox3.Text = "Total " + Environment.NewLine +
Convert.ToString(subtract.Subtraction(Convert.ToInt16(textBox1.Text),
Convert.ToInt16(textBox2.Text)));
break;

case "*":
WindowsFormsApp6.BasicComputations multiply = new
WindowsFormsApp6.BasicComputations();
textBox3.Text = "Total " + Environment.NewLine +
Convert.ToString(multiply.Multiplication(Convert.ToInt16(textBox1.Text),
Convert.ToInt16(textBox2.Text)));
break;

case "/":
if (number2 == 0)
{
MessageBox.Show("Division by ZERO");
}
else
{
WindowsFormsApp6.BasicComputations divide = new
WindowsFormsApp6.BasicComputations();
textBox3.Text = "Total " + Environment.NewLine +
Convert.ToString(divide.Division(Convert.ToInt16(textBox1.Text),
Convert.ToInt16(textBox2.Text)));
}
break;

default:
MessageBox.Show("Operator is Invalid!");
break;
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy