博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
结对编程项目-四则运算
阅读量:5136 次
发布时间:2019-06-13

本文共 16127 字,大约阅读时间需要 53 分钟。

根据冯老师给出的作业我们解决了最基本的功能以及基本设定参数:

   1) 题目的数量(个人项目的要求)

   2) 数值的范围(个人项目的要求)

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

   4) 题目中是否有乘除法

   5) 题目中有无负数

我们本次两个小组合作完成本次作业,我们小组主要负责以下功能:

   1) public void Build_NoMul_NoDiv_NoMinus函数

   2) public void Build_Mul_Div_Minus函数

   3)private string Getstr2函数

1.主界面

2.总体设计

3.主要函数代码

1)public void Build_NoMul_NoDiv_NoMinus函数

public void Build_NoMul_NoDiv_NoMinus(int cal) {            if (cal == 1)            {                int[] num1;                int[] num2;                int i, r1, r2;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s = r1 + r2;                    if ((r1>r2&&s > 0)&&(r1!=0&&r2!=0))                    {                        num1[i] = r1; num2[i] = r2;                    }                    else {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0&&num2[i]!=0)                    {                        listView1.Items.Add("("+num1[i]+")" + Getstr1(1) +"("+ num2[i]+")"+"=");                    }                                    }            }            if (cal == 2) {                int[] num1;                int[] num2;                int[] num3;                int i, r1, r2,r3;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s = r1 + r2 + r3;                    if ((r1>(r2+r3)&&(r2*r3>0)&&s > 0)&&(r1 != 0&&r2 != 0&&r3 != 0))                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0&&num3[i] != 0)                    {                        listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")"+"=");                    }                                   }            }            if (cal == 3) {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int i, r1, r2, r3,r4;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s1 = r1 + r2;                    int s2 = r3 + r4;                    if ((r1>r2&&s1 > 0&&r3>r4&&s2>0) && (r1 != 0&& r2 != 0 &&r3!=0 &&r4!=0))                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4;                    }                    else                    {                        i--;                        continue;                    }                                 }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0&&num4[i]!=0)                    listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + Getstr1(1) + "(" + num4[i] + ")"+"=");                    }            }            if (cal == 4) {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int[] num5;                int i, r1, r2, r3, r4,r5;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                num5 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s=r1+r2+r3+r4+r5;                    int s1 = r1 + r2;                    int s2 = r3 + r4;                    if ((r1>r2&&r3>r4&&s1>0&&s2>0&&s1>(s2+r5)&&s>0&&s2*r5>0) && (r1 != 0&&r2 != 0&&r3 != 0&&r4 != 0&&r5 != 0))                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0&&num5[i]!=0)                    listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + Getstr1(1) + "(" + num4[i] + ")" + Getstr1(1) + "(" + num5[i] + ")"+"=");                                  }            }            if (cal == 5) {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int[] num5;                int[] num6;                int i, r1, r2, r3, r4, r5,r6;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                num5 = new int[100];                num6 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r6 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s = r1 + r2 + r3 + r4 + r5 + r6;                    int s1 = r1 + r2;                    int s2 = r3 + r4;                    int s3 = r5 + r6;                    if ((r1>r2&&s1>0&&r3>r4&&s2>0&&r5>r6&&s3>0) && (r1 != 0&&r2 != 0&&r3 != 0&&r4 != 0&&r5 != 0&& r6 != 0))                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5; num6[i] = r6;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + Getstr1(1) + "(" + num4[i] + ")" + Getstr1(1) + "(" + num5[i] + ")" + Getstr1(1) + "(" + num6[i] + ")"+"=");                            }                            }                 }

2)public void Build_Mul_Div_Minus函数

public void Build_Mul_Div_Minus(int cal)        {            if (cal == 1)            {                int[] num1;                int[] num2;                int i, r1, r2;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    int s = r1 + r2;                    if (r1 != 0 && r2 != 0)                    {                        num1[i] = r1; num2[i] = r2;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0)                    {                        listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + "=");                    }                }            }            if (cal == 2)            {                int[] num1;                int[] num2;                int[] num3;                int i, r1, r2, r3;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    if (r1 != 0 && r2 != 0 && r3 != 0)                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0)                    {                        listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + "=");                    }                }            }            if (cal == 3)            {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int i, r1, r2, r3, r4;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0)                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0)                        listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + Getstr2(1) + "(" + num4[i] + ")" + "=");                }            }            if (cal == 4)            {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int[] num5;                int i, r1, r2, r3, r4, r5;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                num5 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0)                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0 && num5[i] != 0)                        listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + Getstr2(1) + "(" + num4[i] + ")" + Getstr2(1) + "(" + num5[i] + ")" + "=");                }            }            if (cal == 5)            {                int[] num1;                int[] num2;                int[] num3;                int[] num4;                int[] num5;                int[] num6;                int i, r1, r2, r3, r4, r5, r6;                int n = int.Parse(textSum.Text);                Random r = new Random();                num1 = new int[100];                num2 = new int[100];                num3 = new int[100];                num4 = new int[100];                num5 = new int[100];                num6 = new int[100];                for (i = 0; i < n; i++)                {                    r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    r6 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));                    if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0)                    {                        num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5; num6[i] = r6;                    }                    else                    {                        i--;                        continue;                    }                }                for (i = 0; i < n; i++)                {                    listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + Getstr2(1) + "(" + num4[i] + ")" + Getstr2(1) + "(" + num5[i] + ")" + Getstr2(1) + "(" + num6[i] + ")" + "=");                }            }         }

3)private string Getstr2函数

private string Getstr2(int num)        {            string result = "";            for (int i = 0; i < num; i++)            {                int r = r10.Next(strs2.Length);                result += strs2[r];            }            return result;        }

4.总结

    经过这两周断断续续的学习软件工程,终于完成了四则运算。在编码的过程中,在本次项目中我经过大量的访问网上的资源和跟同学的积极讨论完成了并不完善的四则运算。

PS:虽然实现的代码不是很严谨且结构简单,但我希望通过下一次的作业优化并且完善四则运算这个项目。

小组成员:

             李红亮,常宇鹏;

合作小组:

              李成帅,张伟祥;

转载于:https://www.cnblogs.com/hongliang01/p/5358416.html

你可能感兴趣的文章
[ JAVA编程 ] double类型计算精度丢失问题及解决方法
查看>>
好玩的-记最近玩的几个经典ipad ios游戏
查看>>
Sql Server 中由数字转换为指定长度的字符串
查看>>
tmux的简单快捷键
查看>>
[Swift]LeetCode922.按奇偶排序数组 II | Sort Array By Parity II
查看>>
php match_model的简单使用
查看>>
Vue_(组件通讯)子组件向父组件传值
查看>>
STM32单片机使用注意事项
查看>>
移动开发平台-应用之星app制作教程
查看>>
springboot No Identifier specified for entity的解决办法
查看>>
浅谈 unix, linux, ios, android 区别和联系
查看>>
51nod 1428 活动安排问题 (贪心+优先队列)
查看>>
latex for wordpress(一)
查看>>
如何在maven工程中加载oracle驱动
查看>>
aboutMe
查看>>
【Debug】IAR在线调试时报错,Warning: Stack pointer is setup to incorrect alignmentStack,芯片使用STM32F103ZET6...
查看>>
一句话说清分布式锁,进程锁,线程锁
查看>>
FastDFS使用
查看>>
服务器解析请求的基本原理
查看>>
[HDU3683 Gomoku]
查看>>