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

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

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

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

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

       4) 题目中是否有乘除法

       5) 题目中有无负数

    我们本次两个小组合作完成本次作业,我们小组(小组成员  张伟祥,李成帅)主要负责以下功能:

       1) public void Build_Mul_Div_NoMinus函数

       2) public void Build_NoMul_NoDiv_Minus函数

    1.主界面

    2.总体设计

    3.主要函数代码

    public void Build_Mul_Div_NoMinus函数代码如下:
      1 public void Build_Mul_Div_NoMinus(int cal)
      2         {
      3             if (cal == 1)
      4             {
      5                 int[] num1;
      6                 int[] num2;
      7                 int i, r1, r2;
      8                 int n = int.Parse(textSum.Text);
      9                 Random r = new Random();
     10                 num1 = new int[100];
     11                 num2 = new int[100];
     12                 for (i = 0; i < n; i++)
     13                 {
     14 
     15                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     16                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     17                     int s = r1 + r2;
     18                     if ((r1 != 0 && r2 != 0)&&(r1>r2))
     19                     {
     20                         num1[i] = r1; num2[i] = r2;
     21                     }
     22                     else
     23                     {
     24                         i--;
     25                         continue;
     26                     }
     27                 }
     28                 for (i = 0; i < n; i++)
     29                 {
     30 
     31                     if (num1[i] != 0 && num2[i] != 0)
     32                     {
     33 
     34                         listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + "=");
     35                     }
     36 
     37                 }
     38 
     39             }
     40             if (cal == 2)
     41             {
     42                 int[] num1;
     43                 int[] num2;
     44                 int[] num3;
     45                 int i, r1, r2, r3;
     46                 int n = int.Parse(textSum.Text);
     47                 Random r = new Random();
     48                 num1 = new int[100];
     49                 num2 = new int[100];
     50                 num3 = new int[100];
     51                 for (i = 0; i < n; i++)
     52                 {
     53 
     54                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     55                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     56                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     57                     if ((r1 != 0 && r2 != 0 && r3 != 0)&&((r1-r2)>r3)&&(r1>r2)&&(r2>r3))
     58                     {
     59                         num1[i] = r1; num2[i] = r2; num3[i] = r3;
     60                     }
     61                     else
     62                     {
     63                         i--;
     64                         continue;
     65                     }
     66                 }
     67                 for (i = 0; i < n; i++)
     68                 {
     69 
     70                     if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0)
     71                     {
     72 
     73                         listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + "=");
     74                     }
     75 
     76                 }
     77             }
     78             if (cal == 3)
     79             {
     80                 int[] num1;
     81                 int[] num2;
     82                 int[] num3;
     83                 int[] num4;
     84                 int i, r1, r2, r3, r4;
     85                 int n = int.Parse(textSum.Text);
     86                 Random r = new Random();
     87                 num1 = new int[100];
     88                 num2 = new int[100];
     89                 num3 = new int[100];
     90                 num4 = new int[100];
     91                 for (i = 0; i < n; i++)
     92                 {
     93 
     94                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     95                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     96                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     97                     r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     98                     int s1 = r1 - r2;
     99                     int s2 = r3 - r4;
    100                     if ((r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0)&&(r1>r2)&&(r3>r4)&&(s1>s2))
    101                     {
    102                         num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4;
    103                     }
    104                     else
    105                     {
    106                         i--;
    107                         continue;
    108                     }
    109 
    110                 }
    111                 for (i = 0; i < n; i++)
    112                 {
    113                     if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0)
    114                         listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + Getstr2(1) + "(" + num4[i] + ")" + "=");
    115 
    116                 }
    117             }
    118             if (cal == 4)
    119             {
    public void Build_NoMul_NoDiv_Minus代码如下:
      1  public void Build_NoMul_NoDiv_Minus(int cal) {
      2             if (cal == 1)
      3             {
      4                 int[] num1;
      5                 int[] num2;
      6                 int i, r1, r2;
      7                 int n = int.Parse(textSum.Text);
      8                 Random r = new Random();
      9                 num1 = new int[100];
     10                 num2 = new int[100];
     11                 for (i = 0; i < n; i++)
     12                 {
     13 
     14                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     15                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     16                     if (r1!=0&&r2!=0)
     17                     {
     18                         num1[i] = r1; num2[i] = r2;
     19                     }
     20                     else
     21                     {
     22                         i--;
     23                         continue;
     24                     }
     25                 }
     26                 for (i = 0; i < n; i++)
     27                 {
     28 
     29                     if (num1[i] != 0 && num2[i] != 0)
     30                     {
     31 
     32                         listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + "=");
     33                     }
     34 
     35                 }
     36 
     37             }
     38             if (cal == 2)
     39             {
     40                 int[] num1;
     41                 int[] num2;
     42                 int[] num3;
     43                 int i, r1, r2, r3;
     44                 int n = int.Parse(textSum.Text);
     45                 Random r = new Random();
     46                 num1 = new int[100];
     47                 num2 = new int[100];
     48                 num3 = new int[100];
     49                 for (i = 0; i < n; i++)
     50                 {
     51 
     52                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     53                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     54                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     55                     if (r1!=0&&r2!=0&&r3!=0)
     56                     {
     57                         num1[i] = r1; num2[i] = r2; num3[i] = r3;
     58                     }
     59                     else
     60                     {
     61                         i--;
     62                         continue;
     63                     }
     64                 }
     65                 for (i = 0; i < n; i++)
     66                 {
     67 
     68                     if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0)
     69                     {
     70 
     71                         listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + "=");
     72                     }
     73 
     74                 }
     75             }
     76             if (cal == 3)
     77             {
     78                 int[] num1;
     79                 int[] num2;
     80                 int[] num3;
     81                 int[] num4;
     82                 int i, r1, r2, r3, r4;
     83                 int n = int.Parse(textSum.Text);
     84                 Random r = new Random();
     85                 num1 = new int[100];
     86                 num2 = new int[100];
     87                 num3 = new int[100];
     88                 num4 = new int[100];
     89                 for (i = 0; i < n; i++)
     90                 {
     91 
     92                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     93                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     94                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     95                     r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
     96                     if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0)
     97                     {
     98                         num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4;
     99                     }
    100                     else
    101                     {
    102                         i--;
    103                         continue;
    104                     }
    105 
    106                 }
    107                 for (i = 0; i < n; i++)
    108                 {
    109                     if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0)
    110                         listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + Getstr1(1) + "(" + num4[i] + ")" + "=");
    111 
    112                 }
    113             }
    114             if (cal == 4)
    115             {
    116 
    117                 int[] num1;
    118                 int[] num2;
    119                 int[] num3;
    120                 int[] num4;
    121                 int[] num5;
    122                 int i, r1, r2, r3, r4, r5;
    123                 int n = int.Parse(textSum.Text);
    124                 Random r = new Random();
    125                 num1 = new int[100];
    126                 num2 = new int[100];
    127                 num3 = new int[100];
    128                 num4 = new int[100];
    129                 num5 = new int[100];
    130                 for (i = 0; i < n; i++)
    131                 {
    132 
    133                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    134                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    135                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    136                     r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    137                     r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    138                     if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0)
    139                     {
    140                         num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5;
    141                     }
    142                     else
    143                     {
    144                         i--;
    145                         continue;
    146                     }
    147 
    148                 }
    149                 for (i = 0; i < n; i++)
    150                 {
    151                     if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0 && num5[i] != 0)
    152                         listView1.Items.Add("(" + num1[i] + ")" + Getstr1(1) + "(" + num2[i] + ")" + Getstr1(1) + "(" + num3[i] + ")" + Getstr1(1) + "(" + num4[i] + ")" + Getstr1(1) + "(" + num5[i] + ")" + "=");
    153 
    154 
    155                 }
    156             }
    157             if (cal == 5)
    158             {
    159 
    160                 int[] num1;
    161                 int[] num2;
    162                 int[] num3;
    163                 int[] num4;
    164                 int[] num5;
    165                 int[] num6;
    166                 int i, r1, r2, r3, r4, r5, r6;
    167                 int n = int.Parse(textSum.Text);
    168                 Random r = new Random();
    169                 num1 = new int[100];
    170                 num2 = new int[100];
    171                 num3 = new int[100];
    172                 num4 = new int[100];
    173                 num5 = new int[100];
    174                 num6 = new int[100];
    175                 for (i = 0; i < n; i++)
    176                 {
    177 
    178                     r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    179                     r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    180                     r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    181                     r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    182                     r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    183                     r6 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text));
    184                     if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0)
    185                     {
    186                         num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5; num6[i] = r6;
    187                     }
    188                     else
    189                     {
    190                         i--;
    191                         continue;
    192                     }
    193 
    194                 }
    195                 for (i = 0; i < n; i++)
    196                 {
    197                     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] + ")" + "=");
    198 
    199                 }
    200 
    201             } 
    202         
    203         }

    总结:经过了几天的努力,我们共同完成了这次作业,在这期间存在着不同的问题,总之还是觉得自己懂的太少了,应该增加些代码量,做程序的时候不能急,应该一步步的来,问问题也是很重要的一部分,随着计算机技术的成熟,我们应该增加自己对计算机的认识和努力提高我们的专业知识,这次我们通过查找其他人博客学习到了很多东西,总之觉得应该少一些花哨的东西,多务实一点,多打一些代码。

  • 相关阅读:
    CSS——精灵图与背景图片定位
    CSS——text-indent
    CSS——样式隐藏
    CSS——规避脱标流和vertical-align
    CSS——盒子居中显示
    CSS——img
    CSS——position
    CSS——样式初始化
    CSS——清除浮动
    CSS——float
  • 原文地址:https://www.cnblogs.com/lichengshuai/p/5358801.html
Copyright © 2011-2022 走看看