zoukankan      html  css  js  c++  java
  • 第三次作业

    一 、需求分析

    当用户单击开始按钮时程序会自动产生两个随机的数,并且所产生的两个数第一个数一定大于第二个数不会出现出现负数的情况;

    用户可以自己选择时间,时间以秒为单位,时间到了textBox4将不能再输入答案同时Form2也会弹出,统计出结果;

    用户也可以选择计算的总题数,题数做完Form2也会弹出,统计出结果;

    用户不想做时可以单击停止直接统计出结果。

    二、设计思路

    先设计Form1、Form2 并编写代码

    Form1中先获取两个随机数、算法、定时器、计算的总题数

    然后Form2中再编写

    三、插入代码

    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;
               public static int a;
               public static int b;
               public static int t;
               public static int n1;
               public static int n2;
            private void button2_Click(object sender, EventArgs e)
            {
                t = int.Parse(textBox5.Text);
                textBox5.Text = t.ToString();
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
                an();
            }
            private void button3_Click(object sender, EventArgs e)//计算的方法
            {
                
                string z = textBox3.Text;
                string s = textBox4.Text;
    
                int q = int.Parse(s);
                if (z == "+")
                {
    
                    if (q == a + b)
                    {
                        right++;
    
    
    
                    }
                    
    
                }
                if (z == "-")
                {
    
                    if (q == a - b)
                    {
                        right++;
    
                    }
                    
    
                }
                if (z == "*")
                {
    
                    if (q == a * b)
                    {
                        right++;
    
                    }
                    
    
                }
                if (z == "/")
                {
    
                    if (q == a / b)
                    {
                        right++;
    
                    }
                    
    
                }
            
            an();
            } 
            private void an()//随机产生两个数
            {
                Random shu=new Random();
                n1=int.Parse(textBox6.Text)+1;
                n2=int.Parse(textBox7.Text);
                a=shu.Next(n1,n2);
                b=shu.Next(n1,a);
                textBox1.Text = a.ToString();
                textBox2.Text = b.ToString();
                textBox3.Text = "";
                textBox4.Text = "";
                count++;
                
            }
            private void button1_Click_1(object sender, EventArgs e)
            {
                Form2 da = new Form2();
                da.ShowDialog();
            }
            private void timer1_Tick(object sender, EventArgs e)//计时器
            {
                if (t <= 0)
                {
                    timer1.Enabled = false;
                    textBox4.Enabled = false;
                    MessageBox.Show("时间到!");
                    Form2 da = new Form2();
                    da.ShowDialog();
    
    
                }
                t = t - 1;
                textBox5.Text = t.ToString();
            }
            private void textBox4_KeyDown(object sender, KeyEventArgs e)//单击Enter确定计算结果和计算的总题数
            {
                int s;
                s=int.Parse(textBox8.Text);
                if (e.KeyCode == Keys.Enter)
                {
                    
    
                    if (s == count)
                    {
                        textBox4.Enabled = false;
                        Form2 ft = new Form2();
                        ft.ShowDialog();
                    }
                    an();
                }
                   
                
            }
        }
    }

    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耗时

    PSP2.1 Personal Software Process Stages Time(h)
    Planning 计划 10
      • Estimate 估计这个任务需要多长时间 8
    Development 开发  
      • Analysis 需求分析 2
      • Design Spec 生成设计文档  
      • Coding Standard 代码规范 1
      • Design 具体设计 1.5
      • Coding 具体代码 3
      • Code Review 代码复审 1
      • Text 测试 0.5
    Reporting 报告  
      • Test Report 测试报告  
      • Size Measurement 计算工作量

    0.5

      • Postmortem 事后总结

    1.5

    六、总结

    这次作业我在上次作业上稍做添加完成的,这次写完真觉得自己学的不好写,这个程序自己觉得还有些不足,但我们能力有限不知道该如何完善但还会不断的去研究完善它。

    我还希望您能给我提些意见。

  • 相关阅读:
    C#异步编程:多线程基础Thread类
    WPF:TextBox控件禁用中文输入
    C#:泛型的协变和逆变
    C#:泛型接口
    C#:泛型委托
    C#:泛型类
    Jetbrains Rider:缺少.NET Framework 4.5.2
    C#:泛型方法
    C#:泛型
    C#:接口
  • 原文地址:https://www.cnblogs.com/fanxiaotian/p/4887487.html
Copyright © 2011-2022 走看看