结对编程项目---四则运算

小组成员:

陈芝航   学号:118205119    博客地址:http://home.cnblogs.com/u/c131410/

胡运佳   学号:130201230

 结对编程项目---四则运算 

基本功能:

1) 实现一个带有用户界面的四则运算。

2) 生成的题目不能重复。

3) 支持负数。

需要支持的基本设定参数

1) 题目的数量

2) 数值的范围

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

4) 题目中或运算过程中有无有分数

5) 题目中是否有乘除法

6) 题目中是否有括号

7) 题目中或运算过程中有无负数

工作分配:

陈芝航:设计窗体,逻辑规划,部分代码。

胡运佳:整体代码实现,功能调试。

编程代码:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 
 11 namespace 四则运算
 12 {
 13     public partial class Form1 : Form
 14     {
 15         public Form1()
 16         {
 17             InitializeComponent();
 18         }
 19         char[] ysf = { '+', '-', '*', '%', ' ' };
 20         static int GetRandomSeed() 
 21         {
 22             byte[] bytes = new byte[4];
 23             System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
 24             rng.GetBytes(bytes);
 25             return BitConverter.ToInt32(bytes, 0);
 26         }
 27         public void ysfshuchu()
 28         {
 29             shuchu(" "); 
 30             Random rd = new Random(GetRandomSeed());
 31             if (comboBox3.SelectedItem.ToString() == "")
 32             {
 33                 shuchu(ysf[rd.Next(4)].ToString());
 34             }
 35             else
 36             {
 37                 shuchu(ysf[rd.Next(2)].ToString());
 38             }
 39             shuchu(" ");
 40         }
 41         public void cal_1(int r)
 42         {
 43             if (comboBox1.SelectedItem.ToString() == "")   
 44             {
 45                 Random rd = new Random(GetRandomSeed());
 46                 zsfs(r);
 47                 ysfshuchu();  
 48                 zsfs(r);
 49             }
 50             else
 51             {
 52                 Random rd = new Random(GetRandomSeed());
 53                 zs(r);
 54                 ysfshuchu();
 55                 zs(r);
 56             }
 57         }
 58         public void cal_2(int r)
 59         {
 60             Random rd = new Random(GetRandomSeed());
 61             int t = 0;
 62             t = rd.Next(2); 
 63             if (t == 0)
 64             {
 65                 cal_1(r);
 66             }
 67             else
 68             {
 69 
 70                 if (comboBox4.SelectedItem.ToString() == "")  
 71                 {
 72                     input_cal_2kh(r);
 73                 }
 74                 else
 75                 {
 76                     input_cal_2(r);
 77                 }
 78 
 79 
 80             }
 81         }
 82         public void input_cal_2(int r)
 83         {
 84             if (comboBox2.SelectedItem.ToString() == "")  
 85             {
 86                 zsfs(r);
 87                 ysfshuchu();
 88                 zsfs(r);
 89                 ysfshuchu();
 90                 zsfs(r);
 91             }
 92             else
 93             {
 94                 zs(r);
 95                 ysfshuchu();
 96                 zs(r);
 97                 ysfshuchu();
 98                 zs(r);
 99             }
100 
101         }
102         public void input_cal_2kh(int r)
103         {
104             if (comboBox2.SelectedItem.ToString() == "") 
105             {
106                 shuchu("(");
107                 zsfs(r);
108                 ysfshuchu();
109                 zsfs(r);
110                 shuchu(")");
111                 ysfshuchu();
112                 zsfs(r);
113             }
114             else
115             {
116                 shuchu("(");
117                 zs(r);
118                 ysfshuchu();
119                 zs(r);
120                 shuchu(")");
121                 ysfshuchu();
122                 zs(r);
123             }
124 
125         }
126 
127         public void zs(int r) 
128         {
129             Random rd = new Random(GetRandomSeed());
130             int num;
131             do
132             {
133                 num = rd.Next(r + 1);
134             } while (num == 0);
135 
136             shuchu(num.ToString());
137 
138         }
139         public void zsfs(int r) 
140         {
141             int t = 0;
142             Random rd = new Random(GetRandomSeed());
143             t = rd.Next(2); 
144             if (t == 0)
145             {
146                 int num;
147                 do
148                 {
149                     num = rd.Next(r + 1);
150                 } while (num == 0);
151 
152                 shuchu(num.ToString());
153 
154             }
155             else
156             {
157                 fsfs(r);
158             }
159 
160         }
161         public void fsfs(int r) 
162         {
163             Random rd = new Random(GetRandomSeed());
164             int x, y; 
165             do
166             {
167                 x = rd.Next(r + 1);
168             } while (x == 0); 
169             do
170             {
171                 y = rd.Next(r + 1);
172             } while (y == 0 || y == x); 
173 
174             if (x > y) 
175             {
176                 int t = x;
177                 x = y;
178                 y = t;
179             }
180             shuchu(x.ToString());
181             shuchu("/");
182             shuchu(y.ToString());
183 
184 
185         }
186         public void shuchu(string t)
187         {
188             txt_show.AppendText(t);
189         }
190         private void btn_show_Click(object sender, EventArgs e)
191         {
192             int n = Convert.ToInt32(this.txt_n.Text);  
193             int x = Convert.ToInt32(this.txt_r.Text);  
194             int ysf = Convert.ToInt32(this.comboBox1.Text.ToString());
195             for (int i = 0; i < n; i++) 
196             {
197                 if (ysf == 1)  
198                 {
199                     cal_1(x);
200                 }
201                 else if (ysf == 2)  
202                 {
203                     cal_2(x);
204                 }
205                 shuchu(" = ");
206                 shuchu("
");
207                 shuchu("
");
208             }
209         }
210 
211     }
212 }

个人总结:

  通过这次团队合作,让我深知团队是由每一位成员因为一个共同的目标而聚集在一起构成的,这也就是说实效是落实在每一位团队成员身上的。单打独斗不如并肩作战。

原文地址:https://www.cnblogs.com/huyunjia1995/p/5361574.html