博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
结对编程项目---四则运算(代码)
阅读量:5883 次
发布时间:2019-06-19

本文共 5419 字,大约阅读时间需要 18 分钟。

form1

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication2{    public partial class Form1 : Form    {        int n1, n2;        Random ran;        Form2 form2;        public Form1()        {            InitializeComponent();            ran = new Random();            form2 = new Form2();        }        private void button1_Click(object sender, EventArgs e)        {            n1 = ran.Next(int.Parse(textBox1.Text), int.Parse(textBox2.Text));            n2 = ran.Next(int.Parse(textBox1.Text), int.Parse(textBox2.Text));            form2.ShowDialog();        }        private void button2_Click(object sender, EventArgs e)        {            this.Dispose();        }        private void checkBox2_CheckedChanged(object sender, EventArgs e)        {            if (checkBox2.CheckState == CheckState.Checked)            {                button1.Text = "确定 selection is: " + checkBox2.Checked.ToString();                form2.setflag(1);            }        }        private void checkBox3_CheckedChanged(object sender, EventArgs e)        {            if (checkBox3.CheckState == CheckState.Checked)            form2.setflag(0);        }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {            if (comboBox1.SelectedIndex == 0)            {                form2.setnum(10);            }            else                form2.setnum(20);        }        private void checkBox4_CheckedChanged(object sender, EventArgs e)        {        }        private void checkBox1_CheckedChanged(object sender, EventArgs e)        {            form2.fenshu = !form2.fenshu;        }        private void textBox1_TextChanged(object sender, EventArgs e)        {                   }    }}

 

 form2

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication2{    public partial class Form2 : Form    {        int flag;        int num,pos;        double[] ans;        double[] input;        public bool fenshu;        public Form2()        {            InitializeComponent();            flag = 0;            num = 1;            ans = new double[20];            input = new double[20];            fenshu = false;        }        public void setflag(int t) { flag = t; }        public void setnum(int t) { num = t; }        private void button1_Click(object sender, EventArgs e)        {            int yes = 0, no = 0;            for (int i = 0; i < num; i++) {                if (ans[i] == input[i]) yes++;                else no++;            }            Form3 form = new Form3(yes,no);            form.Show();        }        private void button2_Click(object sender, EventArgs e)        {            this.Close();        }        private void button3_Click(object sender, EventArgs e)        {Application.Exit();        }                     private void textBox1_TextChanged(object sender, EventArgs e)        {                        }        private void button4_Click(object sender, EventArgs e)        {            listBox1.Items.Clear();            Random 局部_随机数 = new Random();            for (int i = 0; i < num; i++)            {                int 局部_加数 = 局部_随机数.Next(-100, 100);                int 局部_被加数 = 局部_随机数.Next(-100, 100);                char op;                String t = "";                if (flag == 1)                {                    op = '*';                    ans[i]= 局部_加数 * 局部_被加数;                    t = "" + 局部_加数 + op + 局部_被加数 + "= ";                }                else                {                    op = '/';                    ans[i] = 局部_加数 * 1.0 / 局部_被加数;                    t="" + 局部_加数 + op + 局部_被加数 + "= ";                }                if (fenshu) {                    int temp1,temp2;                    temp1 = 局部_随机数.Next(99)+1;                    temp2 = 局部_随机数.Next(99)+1;                    t = "" + (局部_加数 * temp1) + "/" + temp1 + op + (局部_加数 * temp2) + "/" + temp2;                }                listBox1.Items.Add(t);            }            pos = 0;                    }        private void button5_Click(object sender, EventArgs e)        {            if (pos < num)            {                input[pos++] = Double.Parse(textBox1.Text);                textBox1.Text = "";            }            else            {                textBox1.Text = "over";            }        }    }       }

form3

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication2{    public partial class Form3 : Form    {        public Form3(int yes,int no)        {            InitializeComponent();            textBox1.Text = "" + (yes + no);            textBox2.Text = "" + yes;            textBox3.Text = "" + no;        }        private void Form3_Load(object sender, EventArgs e)        {                   }        private void button1_Click(object sender, EventArgs e)        {            Application.Exit();        }        private void textBox1_TextChanged(object sender, EventArgs e)        {                    }    }}

 

转载于:https://www.cnblogs.com/yanghang0219/p/5338590.html

你可能感兴趣的文章
css important
查看>>
WPF 实现窗体拖动
查看>>
来自维基百科程序员Brandon Harris
查看>>
NULL不是数值
查看>>
CentOS 5 全功能WWW服务器搭建全教程
查看>>
scala111
查看>>
模块化服务规范——OSGI
查看>>
劣质代码评析——猜数字问题(上)
查看>>
纸上谈兵: 栈 (stack)
查看>>
Windows phone8 基础篇(三) 常用控件开发
查看>>
Oracle学习笔记之五,Oracle 11g的PL/SQL入门
查看>>
大叔手记(3):Windows Silverlight/Phone7/Mango开发学习系列教程
查看>>
考拉消息中心消息盒子处理重构(策略模式)
查看>>
so easy 前端实现多语言
查看>>
【追光者系列】HikariCP源码分析之ConcurrentBag&J.U.C SynchronousQueue、CopyOnWriteArrayList...
查看>>
canvas系列教程05-柱状图项目3
查看>>
css绘制几何图形
查看>>
HTML标签
查看>>
理解JS中的Event Loop机制
查看>>
转载:字符编码笔记:ASCII,Unicode和UTF 8
查看>>