结对程序编程-四则运算
根据冯老师给出的作业我们解决了最基本的功能以及基本设定参数:
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.个人感想
这次作业对于我来说很难应为我的底子太差了许多代码看不懂,如果没有李红亮同学帮我可能我根本完不成这次作业。
我打算加紧学习C语言,不能连代码都看不懂。
小组成员:
李红亮,常宇鹏;
合作小组:
李成帅,张伟祥;