软件工程——第三次作业

——题目:

             请编写一个能自动生成小学四则运算题目的 软件

         让程序能接受用户输入答案,并判定对错。           

             最后给出总共 对/错 的数量。

——需求分析:

        软件主要面向小学生,考虑到小学生对计算机的使用和掌握程度有限,所以此软件的操作应尽量简单,易使用;             

        用户能在此"软件"上练习简单的四则运算;            

           软件能提交用户的答案,并判断对错;            

        在使用此 软件后及时给出正确与错误的题目数。

——功能需求:

       首先登陆用户;

       其次,选择计算的数据;

       设计一个时间计时器;

       判断答案对错,给出答案;

       设计计算次数;

——扩展功能:

       程序可以设置答题时间,时间设置为整数,单位为秒,最大不能超过120秒,若超过了答题时间未答题,则提示:时间已到,不能答题。

       用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名

——设计:

        通过利用VS2010进行设计,思想,编码,利用模块化程序的思想进行软件的开发,把里面的函数封装起来,进行调用;

——代码实现:

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)
        {
            jisuan();
        }

        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 = "";
        }

        long second = 120;
        private void timer1_Tick(object sender, EventArgs e)
        {
            second -= 1;
            label12.Text = new DateTime(second * 10000000).ToLongTimeString();
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            label10.Text = textBox5.Text;
        }
        void jisuan()
        {
            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 = "对不起,回答错误!!!"; }
            }
 
        }
    }
}

——实现效果:

    

——设计步骤:

        (1)需求分析

        (2)设计概要

        (3)模块化分析

        (4)代码实现

        (5)单元测试

——PSP

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