作业四

同伴信息

同伴:刘维淇
同伴:马亚坤
班级:计科一班
学号:130201111 130201136

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

对于四则运算项目基本的功能要求:
这次,冯老师给我们的作业要求主要有以下几点:
1.实现一个带有用户界面的四则运算
2.对运算题目的数量做出限制
3.对运算题目的数值范围做出限制
4.对运算题目的有无乘除法做出限制(暂未完成)
我们经过自己组内不断的钻研努力,终于基本完成了这个项目

题型设定

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;
        
        Form2 form2;
        public Form1()
        {
            InitializeComponent();
            
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Random ran = new Random();
            n = Convert.ToInt32(comboBox1.Text.ToString());
            r1 = int.Parse(xiaxian.Text);
            r2 = int.Parse(shangxian.Text);
            if(comboBox2.SelectedItem.ToString() == "包含")
            {
                ysf = 4;
            }
            else
            {
                ysf = 2;
            }
            form2 = new Form3(n, r1, r2, ysf);
            form2.ShowDialog();
        }


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox1.Text = comboBox1.SelectedItem.ToString();
           
        }

    }
}

出题界面

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 Form2(int n, int r1, int r2, int ysf)
        {
            InitializeComponent();
            this.n = n;
            this.r1 = r1;
            this.r2 = r2;
            this.ysf = ysf;
            Form3 form3 = new Form3();
        }

        private void star_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

        private void clear_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void back_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 end_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
    }
}

总结

这次的作业对我们来说难度有一些的大,因为我们本来基本功就不扎实,所以花费了很多的时间,不过在这次作业中我们也学到了很多,团队的合作,虽然以后我以后不会从事计算机的行业,但是我也很享受这个过程!

原文地址:https://www.cnblogs.com/myk130201136/p/5362332.html