2010年11月12日 星期五

期中考2

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        String s = "";
        Double y = 0;
        Double x = 0;
        int d = 0;
        int n = 0;

        private void button16_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "0";
            textBox1.Text = s;
        }
        private void button11_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "0";
            textBox1.Text = s;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "1";
            textBox1.Text = s;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "2";
            textBox1.Text = s;
        }
        private void button4_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "3";
            textBox1.Text = s;
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "4";
            textBox1.Text = s;
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "5";
            textBox1.Text = s;
        }
        private void button7_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "6";
            textBox1.Text = s;
        }
        private void button8_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "7";
            textBox1.Text = s;
        }
        private void button9_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "8";
            textBox1.Text = s;
        }
        private void button10_Click(object sender, EventArgs e)
        {
            if (s == "0") { s = ""; }
            s += "9";
            textBox1.Text = s;
        }
        private void button12_Click(object sender, EventArgs e)
        {
            if (d == 1) { y += Convert.ToDouble(textBox1.Text); }
            else if
            (d == 2) { y -= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 3) { y *= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 4) { y /= Convert.ToDouble(textBox1.Text); }
            else if
            (y == 0) { y = Convert.ToDouble(textBox1.Text); }
            textBox1.Text = Convert.ToString(y);
            d = 1;
            s = "";
        }
        private void button13_Click(object sender, EventArgs e)
        {
            if (d == 1) { y += Convert.ToDouble(textBox1.Text); }
            else if
           (d == 2) { y -= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 3) { y *= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 4) { y /= Convert.ToDouble(textBox1.Text); }
            else if
            (y == 0) { y = Convert.ToDouble(textBox1.Text); }
            textBox1.Text = Convert.ToString(y);
            d = 2;
            s = "";
        }
        private void button14_Click(object sender, EventArgs e)
        {
            if (d == 1) { y += Convert.ToDouble(textBox1.Text); }
            else if
            (d == 2) { y -= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 3) { y *= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 4) { y /= Convert.ToDouble(textBox1.Text); }
            else if
            (y == 0) { y = Convert.ToDouble(textBox1.Text); }
            textBox1.Text = Convert.ToString(y);
            d = 3;
            s = "";
        }
        private void button15_Click(object sender, EventArgs e)
        {
            if (d == 1) { y += Convert.ToDouble(textBox1.Text); }
            else if
           (d == 2) { y -= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 3) { y *= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 4) { y /= Convert.ToDouble(textBox1.Text); }
            else if
            (y == 0) { y = Convert.ToDouble(textBox1.Text); }
            textBox1.Text = Convert.ToString(y);
            d = 4;
            s = "";
        }
        private void button11_Click_1(object sender, EventArgs e)
        {
            s = "";  
            y = 0;
            textBox1.Text = "0";
       
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //determine=> 1=> +  2=> - 3=>*  4=>/   0=> =
            if (d == 1) { y += Convert.ToDouble(textBox1.Text); }
            else if
            (d == 2) { y -= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 3) { y *= Convert.ToDouble(textBox1.Text); }
            else if
            (d == 4) { y /= Convert.ToDouble(textBox1.Text); }
            else if
            (y == 0) { y = Convert.ToDouble(textBox1.Text); }
            else
                y = Convert.ToDouble(textBox1.Text);
            d = 0;
            textBox1.Text = Convert.ToString(y);

        }
        }
    }

沒有留言:

張貼留言