Wednesday, September 8, 2010

C# Code for Arthimatic Calculation by Taking 3 Operands Using Properties Concept -I


/// D.A.Applic_ of Arthimatic Calculation by Taking 3 Operands Using Properties Concept.
Conditions:
Operand1 & Operand2 are Wrie-Only Property whereas Operand3 is Read-Only Property
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

//Property Fields
private int _operand1;
private int _operand2;
private int _result;

//Properties
public int Operand1
{
set { _operand1 = value; }
}
public int Operand2
{
set { _operand2 = value; }
}
public int Result
{
set { _result = value; }
get { return _result; }
}

private void btn_SetValues_Click(object sender, EventArgs e)
{
Operand1 = int.Parse(txt_oper1.Text);
//_operand1 = int.Parse(txt_oper1.Text);
Operand2 = int.Parse(txt_oper2.Text);
//_operand2 = int.Parse(txt_oper2.Text);
}

private void btn_GetValue_Click(object sender, EventArgs e)
{
txt_result.Text = Result.ToString();
//txt_result.Text = obj.Result.ToString();
}

private void btn_Plus_Click(object sender, EventArgs e)
{
Result = _operand1 + _operand2;//Result = Operand1 + Operand2;
btn_GetValue.Enabled = true;
}

private void btn_Subtact_Click(object sender, EventArgs e)
{
Result = _operand1 - _operand2;//Result = Operand1 - Operand2;
btn_GetValue.Enabled = true;
}

private void btn_Multiply_Click(object sender, EventArgs e)
{
Result = _operand1 * _operand2;//Result = Operand1 * Operand2;
btn_GetValue.Enabled = true;
}

private void btn_Division_Click(object sender, EventArgs e)
{
int b = int.Parse(txt_oper2.Text);
if (b != 0)
{
Result = _operand1 / _operand2;//Result = Operand1 / Operand2;
btn_GetValue.Enabled = true;
}
else
MessageBox.Show("Operand2 must not be zero");
}
}
}

No comments:

Post a Comment

Followers