zoukankan      html  css  js  c++  java
  • 实现自动生成30道四则运算题目(4)

    组员:刘伟: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#来完成。

                                                                                 

    六、项目计划总结:

    日期&&任务 听课 编写程序 阅读相关书籍 网上查找资料 日总计
    周一 100 70   15 195
    周二   40 45   95
    周三   50 45 35 120
    周四 100 40 40   180
    周五   90   15 105
    周六     40 15 65
    周日     45   45
    周总

    5时间记录日志:

    日期 开始时间 结束时间 中断时间 净时间 活动 备注
    3/27 14:00 15:50 10 100 听课 软件工程上课
      21:00 21:25   20 阅读书籍  《构建之法》
    3/28 14:00 17:00 10 110 编程 编写作业
      18:00 22:00 10 110 看书 《构建之法》
    3/29 21:00 21:30   30 编程 编写老师布置的作业
    3/30 14:00 15:50 10 100 听课 软件工程上课
    3/31 16:00 18:00   120 编程 编写作业
    4/4 9:00 9:30   30 看书 《构建之法》 《人月神话》
    4/5 9:00 9:30   30 看书 《构建之法》

    6缺陷记录日志:

    日期 编号 类型 引入阶段 排除阶段 修复时间 修复缺陷
    3月26日 1   编码 编码 30min  

    在c#的运用中出现了一些知识问题查阅资料解决

  • 相关阅读:
    Java线程同步synchronized的理解
    MySQL基础操作(二)
    MySQL基础操作(一)
    MySQL备份--xtrabackup与mysqldump工具使用
    MySQL主从复制以及在本地环境搭建
    生活在长大——第一次冲刺小任务
    现代软件工程之敏捷开发
    入门github
    我的编程人生
    Java线程
  • 原文地址:https://www.cnblogs.com/jiajun1/p/5360838.html
Copyright © 2011-2022 走看看