zoukankan      html  css  js  c++  java
  • 作业4(结对编程项目--四则运算)

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

    1.同伴信息:

    班级:13级计科一班

    姓名:赵鑫

    学号:130201118

    2.基本功能

    本次作业是在上次作业的基础之上完成的,也是上次作业的升华。在建立的窗体中你自己可以确定你想出题的数目,并且你也可以确定数值的范围。出题的范围可以是加,减,乘,除任意的,可以是整数也可以是分数。

    3.作业总结

    1、经过这次之后,我深深地体会到了对项目做好规划的重要性。最开始我就是随便看看代码想想算法,但其实在实现的时候才发现很多细节都没有注意到。于是重新根据程序运行顺序读了一遍代码,思考了代码模版的框架,最终完成了这次项目。

    2、由于个人编程能力有限,在修改代码时,之前想过的很多优化都没有实现进去,导致最后程序效率并不高。关于这一点,只能通过今后的锻炼来提升自己,增强编程能力。

    4.运行截图

    5.代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace 四则运算
    {
        public partial class Form1 : Form
        {
            int i, j;
            char[] fh = { '+', '-', '×', '÷' };
           // char[] fs = { ' ', '-' };
            public Form1()
            {
                InitializeComponent();
            }
            static int GetRandomSeed()  //随机数种子,解决随机数一致问题
            {
                byte[] bytes = new byte[4];
                System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
                rng.GetBytes(bytes);
                return BitConverter.ToInt32(bytes, 0);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                i = int.Parse(textBox1.Text);//获取题数
                j = int.Parse(textBox2.Text);//获取运算符数
                int m = 0;
                Random rd = new Random(GetRandomSeed());
                int n=1;
                for (int a = 0; a < i; a++)
                {
                    if (checkBox2.Checked == true)
                    {
                        m = input_qkh(m, n);
                        input_num();
                        for (int b = 0; b < j; b++)
                        {
                            input_fh();
                            //input_fs();
                            if (b < j - n) { m = input_qkh(m, n); }
                            input_num();
                            m = input_hkh(m, n);
                            //input(" ");
    
    
                        }
                        input("=
    ");
                    }
                    else {
                            input_num();
                            for (int b = 0; b < j; b++){
                                input_fh();
                               // input_fs();
                                input_num();
                               // input(" ");
                            }
                                input("=
    ");
                    }
                   
                  
                }
    
    
            }
            public void input_num()
            {
                int a = int.Parse(textBox4.Text);
                int b = int.Parse(textBox5.Text);
    
                if (checkBox3.Checked == true)
                {
                    Random rd = new Random(GetRandomSeed());
                    int c = rd.Next(2);
                    int num1 = rd.Next(a, b + 1);
                    int num2 = rd.Next(0, b + 1);
                    switch (c)
                    {
                        case 0: {
                                input(num1.ToString());
                                input("/");
                                input(num2.ToString());
                            } break;
                        case 1: input(num1.ToString()); break;
                    }
    
                }
                else
                {
                    Random rd = new Random(GetRandomSeed());
                    int num1 = rd.Next(a, b + 1);
                    input(num1.ToString());
                }
            }
            public int input_qkh(int m,int n)//(前括号)m为判定有无前括号,n为后括号添加位置
            {
                
                Random rd = new Random(GetRandomSeed());
                if(m == 0)                //判定有无前括号
                {
                    int a = rd.Next(2);
                    if (a == 0)     //随机概率添加前括号
                    { input("(");
                        m = 1;
                    }
                }
                else
                {
                    
                }
               // input("m=" + m.ToString());
                return m;
                
            }
            public int input_hkh(int m, int n)//(后括号)m为判定有无前括号,n为后括号添加位置
            {
    
                Random rd = new Random(GetRandomSeed());
                if (m == 0)                //判定有无前括号
                {
                    
                }
                else
                {
                    if (m == n + 1)
                    {
                        input(")");
                        m = 0;
                    }
                    else
                    { m++; }
                }
             //   input("m="+m.ToString());
                return m;
    
            }
            /*public void input_fs()
            {
                if (checkBox1.Checked == true)
                {
                    Random rd = new Random(GetRandomSeed());
                    input(fs[rd.Next(2)].ToString());//符号
                }
                else {
                    input(" ");
                }
               
            }*/
            public void input_fh()
            {
                if (checkBox4.Checked == true)
                {
                    Random rd = new Random(GetRandomSeed());
                    input(fh[rd.Next(4)].ToString());//符号
                }
                else {
                    Random rd = new Random(GetRandomSeed());
                    input(fh[rd.Next(2)].ToString());//符号
                }
                
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                textBox3.Text = "";
                textBox1.Text = "";
                textBox2.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
            }
    
         
    
            public void input(string t)
            {
                textBox3.AppendText(t);
            }
    
        }
    }
    
    

    6.合作照片

  • 相关阅读:
    scala中 object 和 class的区别
    scala中的apply方法与unapply方法
    Scala中的样例类详解
    Scala 中下划线的一些魔法
    Hadoop搭建配置参数调优
    设置ESX/ESXi中(Linux)虚拟机从U盘引导启动
    CentOS下编译安装Busybox
    LRU算法简单实现
    Spark 3.0 动态分区裁剪(Dynamic Partition Pruning)
    Hive中的数据分桶以及使用场景
  • 原文地址:https://www.cnblogs.com/zhaosen/p/5361637.html
Copyright © 2011-2022 走看看