前几天过做的,一个可以实现+=部分先后的计算器

时间:2022-12-29 16:03:11

刚学c#请大家轻拍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace jisuanqi
{
    public partial class Form1 : Form
    {
       Queue<double> q = new Queue<double>();//必需加上类型
        Queue<string> fuhao = new Queue<string>();    
        double a, b,d,k;
        bool y=false;
       int c;
        public Form1()
        {
            InitializeComponent();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            b = Convert.ToDouble(textBox1.Text);
            q.Enqueue(b);
            if (fuhao.Count ==1)
            {  k = q.Dequeue();
                d = q.Dequeue();
             
                switch (c)
                {
                    case 0:k += d;break;
                    case 1:k-=d;break;
                    case 2: k *= d; break;
                    case 3: k /= d; break;
                }
               
                q.Enqueue(k);
                fuhao.Dequeue();
            }
                 textBox1.Text = Convert.ToString(k);
                q.Dequeue();          
        }

        private void button11_Click(object sender, EventArgs e)
        {
            c = 0;
            a = Convert.ToDouble(textBox1.Text);
            q.Enqueue(a);
            fuhao.Enqueue(button11.Text);
            if(fuhao.Count>1)
            {
                d = q.Dequeue();
                k = q.Dequeue();
                d += k;
                q.Enqueue(d);
                fuhao.Dequeue();
            } 
            textBox1.Text = "";
          
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
           textBox1.Text += button2.Text; ;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text += button3.Text; ;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text += button4.Text; ;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text += button5.Text;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text += button6.Text;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text += button7.Text;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text += button8.Text;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text += button9.Text;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            textBox1.Text += button10.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text += button1.Text;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            q.Clear();
            fuhao.Clear();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            c = 1;
            a = Convert.ToDouble(textBox1.Text);
            q.Enqueue(a);
            fuhao.Enqueue(button11.Text);
            if (fuhao.Count > 1)
            {
                d = q.Dequeue();
                k = q.Dequeue();
                k += d;
                q.Enqueue(k);
                fuhao.Dequeue();
            }
            textBox1.Text = "";
          
        }

        private void button14_Click(object sender, EventArgs e)
        {
            c = 2;
            a = Convert.ToDouble(textBox1.Text);
            q.Enqueue(a);
            fuhao.Enqueue(button11.Text);
            if (fuhao.Count > 1)
            {
                d = q.Dequeue();
                k = q.Dequeue();
                d += k;
                q.Enqueue(d);
                fuhao.Dequeue();
            }
            textBox1.Text = "";
        }

        private void button15_Click(object sender, EventArgs e)
        {
            c = 3;
            a = Convert.ToDouble(textBox1.Text);
            q.Enqueue(a);
            fuhao.Enqueue(button11.Text);
            if (fuhao.Count > 1)
            {
                d = q.Dequeue();
                k = q.Dequeue();
                d += k;
                q.Enqueue(d);
                fuhao.Dequeue();
            }
            textBox1.Text = "";
        }

        private void button17_Click(object sender, EventArgs e)
        {
            textBox1.Text += button17.Text;
        }
    }
}