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

四则运算

时间:2015-10-01 06:59:18      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

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  int right = 0;//正确的题目个数
        public  int mistake =0;//错误的题目个数
        //随机产生的随机数0-10
        private void RandomNum()
        {
            Random ran = new Random();
            int n1, n2;
            n1 = ran.Next(0, 11);
            n2 = ran.Next(0, 11);
            textBox1.Text = n1.ToString();
            textBox2.Text = n2.ToString();
            textBox3.Text = "";
            
        }       
        public static int sum;
        //调换四则运算的方法
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            textBox3.Focus();
            string str = comboBox1.SelectedItem.ToString(); 
            RandomNum();
            switch (str)
            {
                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;
                case "/":
                    sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
                    break;
            } 
           
        }
        
        //题目的正确个数的题目的错误个数
        private void button3_Click(object sender, EventArgs e)
        {
            textBox3.Focus();
            RandomNum();
            if(textBox3.Text == sum.ToString())
            {
                right++;
                RandomNum();
            }
            else
            {
                mistake++;
                RandomNum();
            }
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
            textBox4.Text = right.ToString();
            textBox5.Text = mistake.ToString() ;
        }
    }
}
Psp分析:
psp Personal Software Process Stages Time
planning 计划       15(m)
Estimate 估计这个任务需要多长时间       1(h)
Development 开发       2(h)
Analysis 需求分析       30(m)
Design Review 设计复审       40(m)
Design 具体设计       20(m)
Code review 代码复审       10(m)
Coding 具体编码       30(m)
Test 测试       1(m)

  技术分享

四则运算

标签:

原文地址:http://www.cnblogs.com/snowz/p/4850605.html

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