zoukankan      html  css  js  c++  java
  • 作业四: 结对编程项目---四则运算

    这是我和本班  韦艺林 学号130201122 博客地址:http://www.cnblogs.com/yilinwei

    功能:我们根据老师提出的作业要求金本上完成了一个带有用户界面的四册运算,可以根据个人要求选择题目数量和取值范围,并可以进行混合四则运算,在原有可以分数运算的基础上加上了正负数运算,使其更加完整。

    我和她的这次作业并未进行详细的分工,我们一起进行了页面的布局的代码的实现。

    优缺点:我们相互指导,有时会就没一段代码发生争吵,但我们会细心听取对方的意见,综合我们的想法去最好的方案。

    结对编程的优缺点:结对编程可以集中所有的的想法,促进编程的实现,正所谓众人拾材火焰高,但是在结对编程中也容易出现问题,发生纠纷,因为每个人都是一个个体,都有自己的想法,有时候很难让对方接受自己的想法,我们也出现过这样的问题,但经过讨论,大家都得到满意的方案。

    结对编程图片:

                 

    以下为本次作业的代码:

    form1

    Form1:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Windows.Forms;
    
    
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btn1_Click(object sender, EventArgs e)
            {
    
                Form2 form = new Form2();
                form.Show();
    
    
            }
    
        }
    
    }
    

    界面:

    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 WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
           
                
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
    
            }
    
            private void ckbZheng_CheckedChanged(object sender, EventArgs e)
            {
                String getnum = txtNum.Text;
                int num = Convert.ToInt32(getnum);  //输入题目
    
                String getmax = txtMax.Text;
                int minnum = Convert.ToInt32(getmax);  //最小范围设定
    
                String getmin = txtMin.Text;
                int maxnum = Convert.ToInt32(getmin);  //最大范围设定
                Random R = new Random();
                int oper = 0;
                for (int i = 0; i < num; i++)
                {
                    int num1, num2;
                    num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    oper = R.Next(0, 3);
                    switch (oper)//0-7分别表示加减乘除
                    {
                        case 0:
                            if (num2 >= 0)
                            { listBox1.Items.Add(num1 + "+" + num2 + "="); }
                            else
                            { listBox1.Items.Add(num1 + "+" + "(" + num2 + ")" + "="); }
                            break;
                        case 1:
                            if (num2 >= 0)
                            { listBox1.Items.Add(num1 + "-" + num2 + "="); }
                            else
                            { listBox1.Items.Add(num1 + "-" + "(" + num2 + ")" + "="); }
                            break;
                        case 2:
                            if (num2 >= 0)
                            { listBox1.Items.Add(num1 + "*" + num2 + "="); }
                            else
                            { listBox1.Items.Add(num1 + "*" + "(" + num2 + ")" + "="); }
                            break;
                        case 3:
                            if (num2 > 0)
                            { listBox1.Items.Add(num1 + "/" + num2 + "="); }
                            else if (num2 < 0)
                            { listBox1.Items.Add(num1 + "/" + "(" + num2 + ")" + "="); }
                            else
                            { i++; }
                            break;
                    }
                }
            }
    
            private void ckbFeng_CheckedChanged(object sender, EventArgs e)
            {
                String getnum = txtNum.Text;
                int num = Convert.ToInt32(getnum);  //输入题目
    
                String getmax = txtMax.Text;
                int minnum = Convert.ToInt32(getmax);  //最小范围设定
    
                String getmin = txtMin.Text;
                int maxnum = Convert.ToInt32(getmin);  //最大范围设定
                Random R = new Random();
                int oper = 0;
                for (int i = 0; i < num; i++)
                {
                    int num1, num2, num3, num4;//num1/num3第一个数;num2/num4第二个数
                    num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    num3 = R.Next(0, int.Parse(txtMax.Text));
                    num4 = R.Next(0, int.Parse(txtMax.Text));
                    oper = R.Next(0, 3);
                    if (num3 != 0)
                    {
                        switch (oper)//0-7分别表示加减乘除
                        {
    
                            case 0:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "+" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 1:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "-" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 2:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "*" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 3:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "/" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                        }
                    }
                    else
                    {
                        i--;
                    }
                }
            }
    
            private void ckbHun_CheckedChanged(object sender, EventArgs e)
            {
                String getnum = txtNum.Text;
                int num = Convert.ToInt32(getnum);  //输入题目
    
                String getmax = txtMax.Text;
                int minnum = Convert.ToInt32(getmax);  //最小范围设定
    
                String getmin = txtMin.Text;
                int maxnum = Convert.ToInt32(getmin);  //最大范围设定
                Random R = new Random();
                int oper = 0;
                for (int i = 0; i < num; i++)
                {
                    int num1, num2, num3, num4;
                    num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text));
                    num3 = R.Next(0, int.Parse(txtMax.Text));
                    num4 = R.Next(0, int.Parse(txtMax.Text));
                    oper = R.Next(0, 7);
                    if (num3 != 0)
                    {
                        switch (oper)//0-7分别表示加减乘除
                        {
                            case 0:
                                if (num2 >= 0)
                                { listBox1.Items.Add(num1 + "+" + num2 + "="); }
                                else
                                { listBox1.Items.Add(num1 + "+" + "(" + num2 + ")" + "="); }
                                break;
                            case 1:
                                if (num2 >= 0)
                                { listBox1.Items.Add(num1 + "-" + num2 + "="); }
                                else
                                { listBox1.Items.Add(num1 + "-" + "(" + num2 + ")" + "="); }
                                break;
                            case 2:
                                if (num2 >= 0)
                                { listBox1.Items.Add(num1 + "*" + num2 + "="); }
                                else
                                { listBox1.Items.Add(num1 + "*" + "(" + num2 + ")" + "="); }
                                break;
                            case 3:
                                if (num2 > 0)
                                { listBox1.Items.Add(num1 + "/" + num2 + "="); }
                                else if (num2 < 0)
                                { listBox1.Items.Add(num1 + "/" + "(" + num2 + ")" + "="); }
                                else
                                { i++; }
                                break;
                            case 4:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "+" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 5:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "-" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 6:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "*" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                            case 7:
                                if (num4 != 0)
                                { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "/" + "(" + num2 + "/" + num4 + ")" + "="); }
                                else
                                { i--; }
                                break;
                        }
                    }
                    else
                    {
                        i--;
                    }
                }
            }
    
            private void button1_Click_1(object sender, EventArgs e)
            {
                txtNum.Text = "";
                txtMin.Text = "";
                txtMax.Text = "";
                listBox1.Items.Clear();
                
    
            }
    
                
        }
    }
    

     界面:

    运行结果:

               

  • 相关阅读:
    django项目的setting、views(视图文件)、urls(新增子路由)和templates文件
    django问题之2:'set' object is not reversible
    django问题之1:ModuleNotFoundError: No module named 'views'
    搭建django环境和简单的开发post、get接口(转载)
    python中的装饰器原理和作用(转载)
    博客园特效(爱心效果、烟花效果、鼠标吸附粒子/斜杆)
    正则表达式的笔记
    第三方支付的测试点【杭州多测师】【杭州多测师_王sir】
    Python题目【杭州多测师】【杭州多测师_王sir】
    查看Nginx是否启动
  • 原文地址:https://www.cnblogs.com/shaomeifu/p/5360449.html
Copyright © 2011-2022 走看看