June 26, 2009

C#-Codes in Arithmetic

Filed under: Summer

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;
        }
    }
}
 

Comments »

The URI to TrackBack this entry is: http://nhingx.blogsome.com/2009/06/26/c-codes-in-arithmetic/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.