Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Activity3Salarda
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmName());
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Activity3Salarda
{
public partial class FrmName : Form
{
private clsArithmetic objArithmetic = new clsArithmetic();
public FrmName()
{
InitializeComponent();
objArithmetic = new clsArithmetic();
}
private void txtNum1_TextChanged(object sender, EventArgs e)
{
try
{
objArithmetic.Num1 = int.Parse(txtNum1.Text);
}
catch (Exception Ex)
{
MessageBox.Show("Incorrect Format.\n" + Ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void txtNum2_TextChanged(object sender, EventArgs e)
{
try
{
objArithmetic.Num2 = int.Parse(txtNum2.Text);
}
catch (Exception Ex)
{
MessageBox.Show("Incorrect Format. \n" + Ex.Message, "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
MessageBox.Show(objArithmetic.getsum().ToString());
}
private void btnSubtract_Click(object sender, EventArgs e)
{
MessageBox.Show(objArithmetic.getdif().ToString());
}
private void btnMultiply_Click(object sender, EventArgs e)
{
MessageBox.Show(objArithmetic.getpro().ToString());
}
private void btnDivide_Click(object sender, EventArgs e)
{
MessageBox.Show(objArithmetic.getquo().ToString());
}
}
}
Class.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Activity3Salarda
{
class clsArithmetic
{
private int _Num1 = 0;
public int Num1
{
get { return _Num1; }
set { _Num1 = value; }
}
private int _Num2 = 0;
public int Num2
{
get { return _Num2; }
set { _Num2 = value; }
}
public int getsum()
{
return _Num1 + _Num2;
}
public int getdif()
{
return _Num1 - _Num2;
}
public int getquo()
{
return _Num1 / _Num2;
}
public int getpro()
{
return _Num1 * _Num2;
}
}
}
