zoukankan      html  css  js  c++  java
  • 结对编程项目——四则运算

    1. 结对编程项目---四则运算 (10分)

    基本功能要求:

    1) 实现一个带有用户界面的四则运算。2) 生成的题目不能重复。3) 支持负数,例如-1,-1/2,-3‘4/5等。(达成)

    需要支持的基本设定参数

    1) 题目的数量  2) 数值的范围  3) 题目中最多几个运算符(目前没有达成)  4) 题目中或运算过程中有无有分数(比如进行整数除法的时候不能除尽) 5) 题目中是否有乘除法  6) 题目中是否有括号 (目前没有达成) 7) 题目中或运算过程中有无负数

           

    学习感受:

    之前自己单独进行作业的时候,会碰上很多的困难自己单独解决不了,就会导致作业的上交延误之类的问题,但是通过这次的两人模式(我们组是三个人进行)搭档来进行编码,我觉得在效率上提高了不少,并且对于作业的认真程度,对项目的理解更是深入了不止一个层次。在进行的过程中,虽然我们也遇到了很多的问题,但通过与大神的交流还有自己查阅一些资料,也顺利的解决了问题,但是还有一些题目的要求我们没有达到要求,之后会继续跟进的。

    结对队友:于悦 http://www.cnblogs.com/yuyue1216/    丁艺朔  http://www.cnblogs.com/dys123hahabalala

     

    代码:

    form 1

    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 WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            Form2 form2;
            public Form1()
            {
                InitializeComponent();
                form2 = new Form2();
            }
    
            private void button0_Click(object sender, EventArgs e)
            {
                String name = this.textBox0.Text; // 获取里面的值
                String password = this.textBox0.Text;
                if (name.Equals("admin") && password.Equals("admin")) // 判断账号密码是否等于admin
                {
                    MessageBox.Show("登录成功");
                    form2.ShowDialog();
                }
                else
                {
                    MessageBox.Show("登录失败!");
                }
                
            }
        }
    }

      

     form 2

    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 WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            int n, r1,r2,ysf;
            
            Form3 form3;
            public Form2()
            {
                InitializeComponent();
                
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                comboBox1.Text = comboBox1.SelectedItem.ToString();
               
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Random ran = new Random();
                n = Convert.ToInt32(comboBox1.Text.ToString());
                r1 = int.Parse(textBox1.Text);
                r2 = int.Parse(textBox2.Text);
                if(comboBox2.SelectedItem.ToString() == "包含")
                {
                    ysf = 4;
                }
                else
                {
                    ysf = 2;
                }
                form3 = new Form3(n, r1, r2, ysf);
                form3.ShowDialog();
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Dispose();
            }
        }
    }

    form 3

    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 WindowsFormsApplication2
    {
        public partial class Form3 : Form
        {
            char[] fuhao = { '+', '-', '*', '%' };
            int n, r1, r2, ysf;
          
      
            public Form3(int n, int r1, int r2, int ysf)
            {
                InitializeComponent();
                this.n = n;
                this.r1 = r1;
                this.r2 = r2;
                this.ysf = ysf;
                Form4 form4 = new Form4();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                string t = "";
                
                Random ran   = new Random();
                for (int i = 0; i < n; i++)
                {
                    int num1 = ran.Next(r1, r2);
                    int num2 = ran.Next(r1, r2);
                    if(ysf == 2)
                    {
                        t = num1 + fuhao[ran.Next(2)].ToString() + num2 + "=";
                    }
                    else
                    {
                        t = num1 + fuhao[ran.Next(4)].ToString() + num2 + "=";
                    }
    
                    listBox1.Items.Add(t);
                }
                
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            
        }
    }

    程序截图:

        

  • 相关阅读:
    编程及应用中的一些快捷键(持续更新中)
    html5入门(head部分的基本认识)
    html5入门(j简单了解html)
    动态规划 ship
    js 解决两值交换
    styled-components解决全局样式'injectGlobal' 废除的问题
    mysql sql更新密码失败
    window nginx 基础命令
    MySQL 8.0
    "unexpected console statement” in Node.js
  • 原文地址:https://www.cnblogs.com/896702797-qw/p/5361252.html
Copyright © 2011-2022 走看看