馮老師給出的作業我們解決了最基本的功能以及基本設定引數:
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 { 120 121 int[] num1; 122 int[] num2; 123 int[] num3; 124 int[] num4; 125 int[] num5; 126 int i, r1, r2, r3, r4, r5; 127 int n = int.Parse(textSum.Text); 128 Random r = new Random(); 129 num1 = new int[100]; 130 num2 = new int[100]; 131 num3 = new int[100]; 132 num4 = new int[100]; 133 num5 = new int[100]; 134 for (i = 0; i < n; i++) 135 { 136 137 r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 138 r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 139 r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 140 r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 141 r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 142 int s1 = r1 - r2; 143 int s2 = r3 - r4; 144 if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && (r1>r2)&&(r3>r4)&&(s1>s2)&&(s1-s2)>r5&&s2>r5) 145 { 146 num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5; 147 } 148 else 149 { 150 i--; 151 continue; 152 } 153 154 } 155 for (i = 0; i < n; i++) 156 { 157 if (num1[i] != 0 && num2[i] != 0 && num3[i] != 0 && num4[i] != 0 && num5[i] != 0) 158 listView1.Items.Add("(" + num1[i] + ")" + Getstr2(1) + "(" + num2[i] + ")" + Getstr2(1) + "(" + num3[i] + ")" + Getstr2(1) + "(" + num4[i] + ")" + Getstr2(1) + "(" + num5[i] + ")" + "="); 159 160 161 } 162 } 163 if (cal == 5) 164 { 165 166 int[] num1; 167 int[] num2; 168 int[] num3; 169 int[] num4; 170 int[] num5; 171 int[] num6; 172 int i, r1, r2, r3, r4, r5, r6; 173 int n = int.Parse(textSum.Text); 174 Random r = new Random(); 175 num1 = new int[100]; 176 num2 = new int[100]; 177 num3 = new int[100]; 178 num4 = new int[100]; 179 num5 = new int[100]; 180 num6 = new int[100]; 181 for (i = 0; i < n; i++) 182 { 183 184 r1 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 185 r2 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 186 r3 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 187 r4 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 188 r5 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 189 r6 = r.Next(int.Parse(textF.Text), int.Parse(textT.Text)); 190 int s1 = r1 - r2; 191 int s2 = r3 - r4; 192 int s3 = r5 - r6; 193 if (r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0 && (r1>r2)&&(r3>r4)&&(r5>r6)&&(s1-s2)>s3&&s1>s2&&s2>s3) 194 { 195 num1[i] = r1; num2[i] = r2; num3[i] = r3; num4[i] = r4; num5[i] = r5; num6[i] = r6; 196 } 197 else 198 { 199 i--; 200 continue; 201 } 202 203 } 204 for (i = 0; i < n; i++) 205 { 206 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] + ")" + "="); 207 208 } 209 210 } 211 212 }
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 }
總結:經過了這些天的努力,我們成功完成了public void Build_Mul_Div_NoMinus函式和public void Build_NoMul_NoDiv_Minus函式的編寫。編寫程式碼的過程中,我們都學到了很多,認識到了程式碼編寫的重要性,我們應該平時多打一些程式碼,熟悉整個程式的設計,這樣切身參與到程式設計當中確實有非常重要的意義。這次的程式碼編寫過程當中,我們也遇到了許多的問題,並且也通過我們的努力解決了這些問題。下次我們會繼續努力!