码迷,mamicode.com
首页 > 其他好文 > 详细

简易计算器

时间:2015-10-07 00:57:02      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

需求分析 :

0到10的整数(随机生成)运算。

思路

技术分享技术分享

代码:

Form1

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 简易计算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public static int Count = 0;
        public static int right = 0;
       

        private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            int sum;
            string a = label1.Text;

            switch (a)
            {
                case "+":
                    sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
                    break;
                case "-":
                    sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
                    break;
                case "*":
                    sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
                    break;
                default:
                    sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
                    break;
            }



            if (e.KeyCode == Keys.Enter)
            {
                if (textBox3.Text == sum.ToString())
                    right++;

                RandomNum();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox3.Enabled = true;
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
        }

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

        private void button4_Click(object sender, EventArgs e)
        {
            label1.Text = "-";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            label1.Text = "*";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            label1.Text = "/";
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            RandomNum();
        }
            private void RandomNum()
        {
            Random random = new Random();
            int number1, number2;
            number1 = random.Next(1, 11);
            number2 = random.Next(1, 11);
            textBox1.Text = number1.ToString();
            textBox2.Text = number2.ToString();
            textBox3.Text = "";
            Count++;

        }
        }
    }

Form2

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 简易计算器
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            textBox1.Text = Form1.Count.ToString();
            textBox2.Text = Form1.right.ToString();
            textBox3.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%";
        }
    }
}

结果:

技术分享

PSP耗时分析:

技术分享

总结:忙了好久,貌似晚了!!不过好歹做出来了,一直也没怎么好好听过课,也有朋友的帮忙,总的感觉还是听有趣的。再接再厉吧。

简易计算器

标签:

原文地址:http://www.cnblogs.com/lmyblogs/p/4858024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!