336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

목표 : 004 프로그램을 기능을 발전시킨다.

 

소스코드 : 

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 WindowsFormsApplication1
{

    public enum Arithmetic
    {
        plus,
        minus,
        multiple,
        division
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.Clear();
        }

        private double GetNum(string str)
        {
            double returnValue = 0;
            if(string.IsNullOrEmpty(str))
            {
                MessageBox.Show("공백 입니다, 숫자를 입력하세요");
                this.Clear();
                throw new Exception("공백 입니다, 숫자를 입력하세요");
            }

            try
            {
                returnValue = double.Parse(str);
            }
            catch
            {
                MessageBox.Show("숫자를 입력하세요");
                this.Clear();
                throw new Exception("숫자를 입력하세요");
            }

            return returnValue;
        }

        private double GetNum1()
        {
            return GetNum(this.textNum1.Text);
        }

        private double GetNum2()
        {
            return GetNum(this.textNum2.Text);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            double num1 = GetNum1();
            double num2 = GetNum2();
            double num = Operate(num1, num2, Arithmetic.plus);

            this.textResult.Text = num.ToString();
            this.lbResult.Text = "+";
        }
        private void btnMinus_Click(object sender, EventArgs e)
        {
            double num1 = GetNum1();
            double num2 = GetNum2();
            double num = Operate(num1, num2, Arithmetic.minus);

            this.textResult.Text = num.ToString();
            this.lbResult.Text = "-";
        }

        private void btnMul_Click(object sender, EventArgs e)
        {
            double num1 = GetNum1();
            double num2 = GetNum2();
            double num = Operate(num1, num2, Arithmetic.multiple);

            this.textResult.Text = num.ToString();
            this.lbResult.Text = "*";
        }

        private void btnDivision_Click(object sender, EventArgs e)
        {
            double num1 = GetNum1();
            double num2 = GetNum2();
            double num = Operate(num1, num2, Arithmetic.division);

            this.textResult.Text = num.ToString();
            this.lbResult.Text = "/";
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            this.Clear();
        }

        private void Clear()
        {
            this.textNum1.Text = "";
            this.textNum2.Text = "";
            this.textResult.Text = "";
            this.lbResult.Text = "Ready";
        }

        private double Operate(double num1, double num2, Arithmetic ari)
        {
            double returnValue = 0.0;

            switch(ari)
            {
                case Arithmetic.plus:
                    returnValue = num1 + num2;
                    break;
                case Arithmetic.minus:
                    returnValue = num1 - num2;
                    break;
                case Arithmetic.multiple:
                    returnValue = num1 * num2;
                    break;
                case Arithmetic.division:                    
                    returnValue = num1 / num2;
                    break;
            }

            return returnValue;
        }


    }
}

 

결과

'Programing C# > C# 200' 카테고리의 다른 글

003 C# 윈도우 프로그래밍  (0) 2020.01.06
002 C# 윈도우 프로그래밍  (0) 2020.01.03
001 C# 프로그래밍 시작하기.  (0) 2019.04.19
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

목표 :

002의 소스코드에 메서드를 만들어 보자

 

소스코드:

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 WindowsFormsApplication1
{

    public enum Arithmetic
    {
        plus,
        minus,
        multiple,
        divison
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.Clear();
        }
        private double GetNum1()
        {
            return double.Parse(this.textNum1.Text);
        }

        private double GetNum2()
        {
            return double.Parse(this.textNum2.Text);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            double num1 = GetNum1();
            double num2 = GetNum2();
            double num = Operate(num1, num2, Arithmetic.plus);

            this.textResult.Text = num.ToString();
            this.lbResult.Text = "+";
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            this.Clear();
        }

        private void Clear()
        {
            this.textNum1.Text = "";
            this.textNum2.Text = "";
            this.textResult.Text = "";
            this.lbResult.Text = "Ready";
        }

        private double Operate(double num1, double num2, Arithmetic ari)
        {
            double returnValue = 0.0;

            switch(ari)
            {
                case Arithmetic.plus:
                    returnValue = num1 + num2;
                    break;
                case Arithmetic.minus:
                    returnValue = num1 - num2;
                    break;
                case Arithmetic.multiple:
                    returnValue = num1 * num2;
                    break;
                case Arithmetic.divison:                    
                    returnValue = num1 / num2;
                    break;
            }

            return returnValue;
        }
    }
}

'Programing C# > C# 200' 카테고리의 다른 글

005 C# 윈도우 프로그래밍 발전  (0) 2020.01.08
002 C# 윈도우 프로그래밍  (0) 2020.01.03
001 C# 프로그래밍 시작하기.  (0) 2019.04.19
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

목표 :

mini 계산기를 만들어 본다.

 

소스코드 : 

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.textNum1.Text = "";
            this.textNum2.Text = "";
            this.textResult.Text = "";
            this.lbResult.Text = "Ready";
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            double num1 = double.Parse(this.textNum1.Text);
            double num2 = double.Parse(this.textNum2.Text);
            double num = num1 + num2;
            this.textResult.Text = num.ToString();
            this.lbResult.Text = "+";
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            this.textNum1.Text = "";
            this.textNum2.Text = "";
            this.textResult.Text = "";
            this.lbResult.Text = "Ready";
        }
    }
}

 

결과 :

'Programing C# > C# 200' 카테고리의 다른 글

005 C# 윈도우 프로그래밍 발전  (0) 2020.01.08
003 C# 윈도우 프로그래밍  (0) 2020.01.06
001 C# 프로그래밍 시작하기.  (0) 2019.04.19
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1. 목표 :

기본 C# 프로그래밍을 작성하여 보자.

 

2. 소스코드 :

Program.cs

using System;// 기본 인클루드 개념
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
// using System.Threading.Tasks;

namespace Com._001.mochi
{
    class mochi_001
    {
        static void Main(string[] args)
        {
            Console.WriteLine("두수를 입력하면 덧셈을 해드립니다.");
            // Console.WriteLine 은 자동 개행이 이뤄지는 함수이다.

            Console.Write("첫 번째 : "); 
            // Consle.Write은 자동 개행이 이뤄지는 함수가 아니다.

            int nFirst = int.Parse(Console.ReadLine()); 
            // int는 자료형이며 클래스다. Console.ReadLine으로 입력받은 값을 int.Parse로
            // 읽어들인 string 을 integer 로 변환하고 그값을 nFirst에 복사한다.

            Console.Write("두 번째 : ");

            int nSecond = int.Parse(Console.ReadLine());

            Console.WriteLine("{0} + {1} = {2}",nFirst, nSecond, (nFirst + nSecond));
            // Console.WriteLine의 기능으로 {}중괄호 안에 내용의 순서를 정할수 있다.
            // 예를들어 Console.WriteLine("{2} = {1} + {0}", nFirst, nSecond, (nFirst + nSecond));
            // 라고 할 경우 3 = 2 + 1과 같은 결과를 얻을 수 있다.

            Console.WriteLine("{2} = {1} + {0}", nFirst, nSecond, (nFirst + nSecond));
        }
    }
}

3. 결과

 

 

먹고 살려면 해야지 cpp로 먹고 살긴 힘들듯하당...

정말 개발자로 먹고 살려면 한가지 언어로는 진심 힘들다.

'Programing C# > C# 200' 카테고리의 다른 글

005 C# 윈도우 프로그래밍 발전  (0) 2020.01.08
003 C# 윈도우 프로그래밍  (0) 2020.01.06
002 C# 윈도우 프로그래밍  (0) 2020.01.03

+ Recent posts