• 作业四


    小组成员:

    王浩淳    学号:130201216     博客地址:http://www.cnblogs.com/wanghaochun/

    吴献荣

     结对编程项目---四则运算 

    基本功能:

    1) 实现一个带有用户界面的四则运算。

    2) 生成的题目不能重复。

    3) 支持负数。

    需要支持的基本设定参数

    1) 题目的数量

    2) 数值的范围

    3) 题目中最多几个运算符

    4) 题目中或运算过程中有无有分数

    5) 题目中是否有乘除法

    6) 题目中是否有括号

    7) 题目中或运算过程中有无负数

    工作分配:

    王浩淳:窗体框架的设计与实现,总体代码功能的设计,bug排除。

    吴献荣:功能代码的实现,整体代码规范,代码细节与bug排除。

    合作人的优缺点:

    优点:1、遇到问题反应快;2、有耐心;3、做事认真

    缺点:1、动手能力较弱

    结对编程的优点和缺点:

     优点:编程效率更高,能力互补,相互学习更有效的解决问题

     缺点:有时想法不统一,编程习惯不同

    编程代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 四则运算自动生成器
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            char[] fh = { '+', '-', '*', '/' };
    
            private void button2_Click(object sender, EventArgs e)
            {
                int a = Convert.ToInt32(this.textBox1.Text);  //获取生成题目数
                int b = Convert.ToInt32(this.textBox2.Text);  //获取生成数的最小值
                int c = Convert.ToInt32(this.textBox3.Text);  //获取生成数的最大值
                int fhs = Convert.ToInt32(this.comboBox1.Text.ToString());  //获取运算符个数
                for (int i = 0; i < a; i++)
                {
                    if (fhs == 1)//一个运算符
                    {
                        if (checkBox1.Checked == true)//有分数
                        {
                            if (checkBox2.Checked == true)//有乘除法
                            {
                                shu(b, c);
                                fh1();
                                shu(b, c);
                                input(" = ");
                                input("
    ");
                            }
                            else
                            {
                                shu(b, c);
                                fh2();
                                shu(b, c);
                                input(" = ");
                                input("
    ");
                            }
                        }
                        else
                        {
                            if (checkBox2.Checked == true)//有乘除法
                            {
                                randzs(b, c);
                                fh1();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                            else
                            {
                                randzs(b, c);
                                fh2();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                        }
                    }
                    else if (fhs == 2)
                    {
                        if (checkBox1.Checked == true)//有分数
                        {
                            if (checkBox2.Checked == true)//有乘除法
                            {
                                if (checkBox3.Checked == true)//有括号
                                {
                                    input("(");
                                    shu(b, c);
                                    fh1();
                                    shu(b, c);
                                    input(")");
                                    fh1();
                                    shu(b, c);
                                    input(" = ");
                                    input("
    ");
                                }
                                else
                                {
                                    shu(b, c);
                                    fh1();
                                    shu(b, c);
                                    fh1();
                                    shu(b, c);
                                    input(" = ");
                                    input("
    ");
                                }
                            }
                        }
                        else
                        {
                            if (checkBox3.Checked == true)//有括号
                            {
                                input("(");
                                shu(b, c);
                                fh2();
                                shu(b, c);
                                input(")");
                                fh2();
                                shu(b, c);
                                input(" = ");
                                input("
    ");
                            }
                            else
                            {
                                shu(b, c);
                                fh2();
                                shu(b, c);
                                fh2();
                                shu(b, c);
                                input(" = ");
                                input("
    ");
                            }
                        }
                    }
                    else
                    {
                        if (checkBox2.Checked == true)//有乘除法
                        {
                            if (checkBox3.Checked == true)//有括号
                            {
                                input("(");
                                randzs(b, c);
                                fh1();
                                randzs(b, c);
                                input(")");
                                fh1();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                            else
                            {
                                randzs(b, c);
                                fh1();
                                randzs(b, c);
                                fh1();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                        }
                        else
                        {
                            if (checkBox3.Checked == true)//有括号
                            {
                                input("(");
                                randzs(b, c);
                                fh2();
                                randzs(b, c);
                                input(")");
                                fh2();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                            else
                            {
                                randzs(b, c);
                                fh2();
                                randzs(b, c);
                                fh2();
                                randzs(b, c);
                                input(" = ");
                                input("
    ");
                            }
                        }
                    }
                }
            }
    
    
            public void fh1() //含有乘除法
            {
                String fh1;
                System.Random i = new Random(System.DateTime.Now.Millisecond);
                fh1 = fh[i.Next(4)].ToString();
                input(fh1);
            }
    
            public void fh2()//无乘除法
            {
                String fh2;
                System.Random i = new Random(System.DateTime.Now.Millisecond);
                fh2 = fh[i.Next(2)].ToString();
                input(fh2);
            }
    
            public void randzs(int b,int c)//随机整数
            {
                int zs;
                System.Random num = new Random(System.DateTime.Now.Millisecond);
                zs = num.Next(b, c);
                input(zs.ToString());
            }
    
            public void randfs(int b,int c)//随机分数
            {
                int n, m;
                System.Random num = new Random(System.DateTime.Now.Millisecond);
                do
                {
                    n = num.Next(b, c);
                    m = num.Next(b, c);
                } while (n == 0 || m == 0 || n == m);
                input(n.ToString());
                input("/");
                input(m.ToString());
            }
    
           public void shu(int b,int c)
            {
                int e;
                System.Random num = new Random(System.DateTime.Now.Millisecond);
                e = num.Next(2);
                if (e == 0) { randzs(b,c); }
                else { randfs(b,c);  }
            }
    
            public void input(string t)//输出到TextBox4中
            {
                textBox4.AppendText(t);
            }
    
            private void button3_Click(object sender, EventArgs e)//清除输出结果
            {
                textBox4.Clear();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                comboBox1.Text = "请选择";
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
            }
        }
    
        }

    窗体框架:

    运行结果截图:

    总结:

    经历了近两周对自动生成四则运算器的编程,我们小组完成了老师发布的任务。同时在这编程的过程中我们懂了很多,也成长了很多,不管是编程方面还是心性方面都有极大的提高。特别是到了完成的那一刻我觉得结果虽然重要但远远比不上编程的过程。

    小组编程截图:

  • 相关阅读:
    18个功能强大的HTML5 和JavaScript游戏引擎库
    10 个超棒的 jQuery 视频插件
    HTML5播放视频音频
    CSS代码重构与优化之路
    推荐10款web前端的 HTML5 开发框架和开发工具
    JS中日期相关函数
    技术笔记1:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password)
    图解HTTP阅读笔记(1)-网络基础TCP/IP
    框架和设计模式的区别
    SSH与MVC
  • 原文地址:https://www.cnblogs.com/bgdwxr/p/5360978.html
Copyright © 2020-2023  润新知