结对编程项目-四则运算
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了结对编程项目-四则运算相关的知识,希望对你有一定的参考价值。
根据冯老师给出的作业我们解决了最基本的功能以及基本设定参数:
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:虽然实现的代码不是很严谨且结构简单,但我希望通过下一次的作业优化并且完善四则运算这个项目。
以上是关于结对编程项目-四则运算的主要内容,如果未能解决你的问题,请参考以下文章