四则运算 改后

 题目编写一个能对0--10之间的整数进行四则运算的“软件”;
         程序能接收用户输入的整数答案,并判断对错;
         程序结束时,统计出答对、答错的题目数量。
补充说明0——10的整数是随机生成的;
          用户可以用键盘输入来选择四则运算中的一种,比如输入1代表加法运算;
          用户用键盘输入一个字符来结束程序的运行并显示统计结果,比如输入e程序结束并显示统计结果              编程语言不限制,命令行输出和图像界面输出都可以。

1.需求分析

设计环境:C#窗体应用程序;

目的:能进行0—10之间随机的整数四则运算;

        接受整数答案,判断对错可以统计答对答错的题数;

代码的设计思路:

代码具体设计:

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;
        public static int wrong = 0;
        private void RandomNum()
        {
            Random ran = new Random();
            int a, b;
            a = ran.Next(1, 11);
            b = ran.Next(1, 11);
            textBox1.Text = a.ToString();
            textBox2.Text = b.ToString();
            textBox3.Text = "";
        }

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

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

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

        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)
        {
            int sum;
            string i = label1.Text;
            if (label1.Text == "+")
                sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);
            else if (label1.Text == "-")
                    sum = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
            else if (label1.Text == "*")
                        sum = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
            else if (label1.Text == "/")
                            sum = int.Parse(textBox1.Text) / int.Parse(textBox2.Text);
            if (textBox3.Text == sum.ToString())
                right++;
            else
                wrong++;
            RandomNum();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
        }
        private void button6_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Form2 frm2 = new Form2();
                frm2.ShowDialog();
            }
        }
        private void button1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                label1.Text = "+";
            }
        }
        private void button2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.S)
            {
                label1.Text = "-";
            }
        }
        private void button3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.D)
            {
                label1.Text = "*";
            }
        }
        private void button4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F)
            {
                label1.Text = "/";
            }
        }
    }
}
             
         

  

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.right.ToString();
            textBox2.Text = Form1.wrong.ToString();
            textBox3.Text = ((Form1.right / (double)(Form1.count) *
                100).ToString() + "%");
        }
    }
}

PSP耗时分析:

 
估计需要的时间 12小时
需求分析 30分钟
生成设计文档 30分钟
设计复审 30分钟
代码规范 1小时
具体设计 3小时
具体编码 3小时
代码复审 1小时
测试 30分钟
测试报告 30分钟
报告总结 30分钟

报告总结:

 运行出来了,这是截图。底子太薄弱了,以后我会找些例子练习练习的;

运行代码如下:





原文地址:https://www.cnblogs.com/mhwgo2205509957/p/4857827.html