您的位置:首页 > 其它

实现自动生成30道四则运算题目(4)

2016-03-19 19:47 411 查看
组员:刘伟:http://www.cnblogs.com/Lw-1573/

一、升级要求:让程序能接受用户输入答案,并判定对错。最后给出总共对/错的数量。

二、设计思想:

这次采用的C#制作的图形化的四则运算程序。

三、源代码

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 四则运算2._0
12 {
13     public partial class Form1 : Form
14     {
15         int shumu = 0;
16         int min = 0;
17         int max = 0;
18         string allfuhao;
19         string fuhao;
20         public Form1()
21         {
22             InitializeComponent();
23         }
24         private void Form1_Load(object sender, EventArgs e)
25         {
26             richTextBox1.Clear();
27             textBox2.Clear();
28             textBox3.Clear();
29             textBox4.Clear();
30         }
31         private void checkBox2_CheckedChanged(object sender, EventArgs e)
32         {
33
34         }
35
36         private void richTextBox1_TextChanged(object sender, EventArgs e)
37         {
38
39         }
40
41         private void textBox4_TextChanged(object sender, EventArgs e)
42         {
43
44         }
45
46         private void label2_Click(object sender, EventArgs e)
47         {
48
49         }
50
51         private void button2_Click(object sender, EventArgs e)
52         {
53             shumu = int.Parse(textBox3.Text);
54             min = int.Parse(textBox4.Text);
55             max = int.Parse(textBox2.Text);
56             System.Random number = new Random(System.DateTime.Now.Millisecond);
57             //循环输出题目
58             for (int i = 0; i <shumu; i++)
59             {
60                 int num1 = number.Next(min, max);
61                 int num2 = number.Next(min, max);
62                 int num3 = number.Next(min, max);
63                 int yunsuan1 = number.Next(0, 4);
64                 int yunsuan2 = number.Next(0, 2);
65                 //定义变量
66                 int fuhaonum = number.Next(0, 2);
67                 if (fuhaonum == 0)//符号进行随机
68                 {
69                     fuhao = "+";
70                 };
71                 if (fuhaonum == 1)
72                 {
73                     fuhao = "-";
74                 };
75                 int allfuhaonum = number.Next(0, 4);
76                 if (allfuhaonum == 0)
77                 {
78                     allfuhao = "+";
79                 };
80                 if (allfuhaonum == 1)
81                 {
82                     allfuhao = "-";
83                 };
84                 if (allfuhaonum == 2)
85                 {
86                     allfuhao = "*";
87                 };
88                 if (allfuhaonum == 3)
89                 {
90                     allfuhao = "/";
91                 };
92
93                 if (checkBox4.Checked == true)//有括号
94                 {
95                     richTextBox1.Text += num3;
96                     if (checkBox1.Checked == true)//有乘除
97                     {
98                         if (checkBox3.Checked == true)//结果允许为负
99                         {
100                             if (yunsuan1 == 0) { richTextBox1.Text += allfuhao + "(" + num1 + "+" + num2 + ")" + "="+"     "; }
101                             else if (yunsuan1 == 1) { richTextBox1.Text += allfuhao + "(" + num1 + "*" + num2 + ")" + "=" + "     "; }
102                             else if (yunsuan1 == 2) { richTextBox1.Text += allfuhao + "(" + num1 + "-" + num2 + ")" + "=" + "     "; }//减法有负数
103                             else if (yunsuan1 == 3 && num2 != 0) { richTextBox1.Text += allfuhao + "(" + num1 + "/" + num2 + ")" + "=" + "     "; }//除法有余数
104                         }
105                         else if(checkBox3.Checked == false)//结果不允许为负
106                         {
107                             if (yunsuan1 == 0) { richTextBox1.Text += allfuhao + "(" + num1 + "+" + num2 + ")" + "=" + "     "; }
108                             else if (yunsuan1 == 1) { richTextBox1.Text += allfuhao + "(" + num1 + "*" + num2 + ")" + "=" + "     "; }
109                             else if (yunsuan1 == 2 && num1 > num2) { richTextBox1.Text += allfuhao + "(" + num1 + "-" + num2 + ")" + "=" + "     "; }//减法无负数
110                             else if (yunsuan1 == 2 && num1 < num2) { richTextBox1.Text += allfuhao + "(" + num2 + "-" + num1 + ")" + "=" + "     "; }//减法无负数
111                             else if (yunsuan1 == 3 && num2 != 0) { richTextBox1.Text += allfuhao + "(" + num1 + "/" + num2 + ")" + "=" + "     "; }//除法有余数
112                         }
113                     }
114                     else if(checkBox1.Checked == false)//没有乘除法
115                         if (checkBox3.Checked == true)//减法有负数
116                         {
117                             if (yunsuan2 == 0) { richTextBox1.Text += fuhao + "(" + num1 + "+" + num2 + ")" + "=" + "     "; }
118                             else if (yunsuan2 == 1) { richTextBox1.Text += fuhao + "(" + num1 + "-" + num2 + ")" + "=" + "     "; }//减法有负数
119                         }
120                         else if (checkBox3.Checked == false)//结果不允许为负
121                         {
122                             if (yunsuan2 == 0) { richTextBox1.Text += fuhao + "(" + num1 + "+" + num2 + ")" + "=" + "     "; }
123                             else if (yunsuan2 == 1 && num1 > num2) { richTextBox1.Text += fuhao + "(" + num1 + "-" + num2 + ")" + "=" + "     "; }//减法无负数
124                             else if (yunsuan2 == 1 && num1 <= num2) { richTextBox1.Text += fuhao + "(" + num2 + "-" + num1 + ")" + "=" + "     "; }//减法无负数
125                         }
126                 }
127                 else if (checkBox4.Checked == false)//没有括号
128                 {
129                     if (checkBox1.Checked == true)//有乘除
130                     {
131                         if (checkBox3.Checked == true)//结果允许为负
132                         {
133                             if (yunsuan1 == 0) { richTextBox1.Text += num1 + "+" + num2 + "=" + "     "; }
134                             else if (yunsuan1 == 1) { richTextBox1.Text += num1 + "*" + num2 + "=" + "     "; }
135                             else if (yunsuan1 == 2) { richTextBox1.Text += num1 + "-" + num2 + "=" + "     "; }//减法有负数
136                             else if (yunsuan1 == 3 && num2 != 0) { richTextBox1.Text += num1 + "/" + num2 + "=" + "     "; }//除法有余数
137                         }
138                         else if (checkBox3.Checked == false)//结果不允许为负
139                         {
140                             if (yunsuan1 == 0) { richTextBox1.Text += num1 + "+" + num2 + "=" + "     "; }
141                             else if (yunsuan1 == 1) { richTextBox1.Text += num1 + "*" + num2 + "=" + "     "; }
142                             else if (yunsuan1 == 2 && num1 > num2) { richTextBox1.Text += num1 + "-" + num2 + "=" + "     "; }//减法无负数
143                             else if (yunsuan1 == 2 && num1 <= num2) { richTextBox1.Text += num2 + "-" + num1 + "=" + "     "; }//减法无负数
144                             else if (yunsuan1 == 3 && num2 != 0) { richTextBox1.Text += num1 + "/" + num2 + "=" + "     "; }//除法有余数
145                         }
146                     }
147                     else if (checkBox1.Checked == false)//没有乘除法
148                          if (checkBox3.Checked == true)//结果允许为负
149                         {
150                             if (yunsuan2 == 0) { richTextBox1.Text += num1 + "+" + num2 + "=" + "     "; }
151                             else if (yunsuan2 == 1) { richTextBox1.Text += num1 + "-" + num2 + "=" + "     "; }//减法有负数
152                         }
153                          else if (checkBox3.Checked == false)//结果不允许为负
154                          {
155                              if (yunsuan2 == 0) { richTextBox1.Text += num1 + "+" + num2 + "=" + "     "; }
156                              else if (yunsuan2 == 1 && num1 > num2) { richTextBox1.Text += num1 + "-" + num2 + "=" + "     "; }//减法无负数
157                              else if (yunsuan2 == 1 && num1 <= num2) { richTextBox1.Text += num2 + "-" + num1 + "=" + "     "; }//减法无负数
158                          }
159                 }
160             }
161
162         }
163
164         private void button1_Click(object sender, EventArgs e)
165         {
166             richTextBox1.Clear();
167             textBox4.Text = "";
168             textBox3.Text = "";
169             textBox2.Text = "";
170             checkBox1.Checked = false;
171             checkBox2.Checked = false;
172             checkBox3.Checked = false;
173             checkBox4.Checked = false;
174         }
175
176         private void textBox2_TextChanged(object sender, EventArgs e)
177         {
178
179         }
180
181         private void textBox3_TextChanged(object sender, EventArgs e)
182         {
183
184         }
185
186         private void groupBox1_Enter(object sender, EventArgs e)
187         {
188
189         }
190
191         private void checkBox1_CheckedChanged(object sender, EventArgs e)
192         {
193
194         }
195
196         private void checkBox4_CheckedChanged(object sender, EventArgs e)
197         {
198
199         }
200
201         private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
202         {
203
204         }
205
206         private void checkBox3_CheckedChanged(object sender, EventArgs e)
207         {
208
209         }
210
211         private void button3_Click(object sender, EventArgs e)
212         {
213             textBox4.Text = "";
214             textBox3.Text = "";
215             textBox2.Text = "";
216         }
217
218         private void button4_Click(object sender, EventArgs e)
219         {
220             checkBox1.Checked = false;
221             checkBox2.Checked = false;
222             checkBox3.Checked = false;
223             checkBox4.Checked = false;
224         }
225     }
226 }


四、结果截图









五、心得体会:

这次的作业由于以前的代码量太大,改起来也不方便,bug也有很多,所以打算另辟蹊径用c#来完成。

六、项目计划总结:

日期&&任务听课编写程序阅读相关书籍网上查找资料日总计
周一1007015195
周二404595
周三504535120
周四1004040180
周五9015105
周六401565
周日4545
周总
5时间记录日志:

日期开始时间结束时间中断时间净时间活动备注
3/2714:0015:5010100听课软件工程上课
21:0021:2520阅读书籍《构建之法》
3/2814:0017:0010110编程编写作业
18:0022:0010110看书《构建之法》
3/2921:0021:3030编程编写老师布置的作业
3/3014:0015:5010100听课软件工程上课
3/3116:0018:00120编程编写作业
4/49:009:3030看书《构建之法》 《人月神话》
4/59:009:3030看书《构建之法》
6缺陷记录日志:

日期编号类型引入阶段排除阶段修复时间修复缺陷
3月26日1编码编码30min在c#的运用中出现了一些知识问题查阅资料解决

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: