软件工程--第二次作业

 

      • 题目:  请编写一个能自动生成小学四则运算题目的 “软件”。           让程序能接受用户输入答案,并判定对错。           最后给出总共 对/错 的数量。

        需求分析:基本功能,能满足用户完成简单的加,减,乘,除运算,每次计算能统计计算的次数,用户给出答案,可与

                      电脑答案匹配,错误与正确都会出现相应的提示框!

        设计:利用VS2010为平台,用C#语言编写,用一个全局变量来记录运算次数,其余的都是用相应控件的属性编写,特别注意整形与字符型之间的装换关系,利用if语句对每种可能进行了选择!

        代码实现:

        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();
                }
        
                private void domainUpDown1_SelectedItemChanged(object sender, EventArgs e)
                {
        
                }
                int s = 0;
                private void button1_Click(object sender, EventArgs e)
                {
                    if (textBox1.Text == null || textBox2.Text == null || textBox3.Text == null)
                    {
                        MessageBox.Show("计算的数字和你所填的答案不能为空");
                    }
                    else
                    {
                        s = s + 1;
                        label6.Text = s.ToString();
                        int a, b;
                        int c;
                        a = Int32.Parse(textBox1.Text);
                        b = Int32.Parse(textBox2.Text);
                        if (comboBox1.Text == "")
                        { c = a + b; textBox3.Text = c.ToString(); }
                        if (comboBox1.Text == "")
                        { c = a - b; textBox3.Text = c.ToString(); }
                        if (comboBox1.Text == "")
                        { c = a * b; textBox3.Text = c.ToString(); }
                        if (comboBox1.Text == "")
                        { c = a / b; textBox3.Text = c.ToString(); }
                        if (textBox3.Text == textBox4.Text)
                        {
                            label4.Text = "恭喜你,计算正确!!!!";
                        }
                        else { label4.Text = "对不起,回答错误!!!"; }
                    }
                }
        
                private void label2_Click(object sender, EventArgs e)
                {
        
                }
        
                private void Form1_Load(object sender, EventArgs e)
                {
        
                }
        
                private void button2_Click(object sender, EventArgs e)
                {
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    comboBox1.Text = "";
                    label6.Text = "";
                }
            }
        }

        程序运行截图:

        分析与总结:这次运算过于简单,因为我没有进行混合运算,导致程序还是没什么难度,不过通过这次的学习,我会把它继续改进的!

        PSP耗时统计:

原文地址:https://www.cnblogs.com/ZYzhangying/p/4410252.html