這是我和本班 韋藝林 學號130201122 博客地址:http://www.cnblogs.com/yilinwei編程
功能:咱們根據老師提出的做業要求金本上完成了一個帶有用戶界面的四冊運算,能夠根據我的要求選擇題目數量和取值範圍,並能夠進行混合四則運算,在原有能夠分數運算的基礎上加上了正負數運算,使其更加完整。dom
我和她的此次做業並未進行詳細的分工,咱們一塊兒進行了頁面的佈局的代碼的實現。佈局
優缺點:咱們相互指導,有時會就沒一段代碼發生爭吵,但咱們會細心聽取對方的意見,綜合咱們的想法去最好的方案。this
結對編程的優缺點:結對編程能夠集中全部的的想法,促進編程的實現,正所謂衆人拾材火焰高,可是在結對編程中也容易出現問題,發生糾紛,由於每一個人都是一個個體,都有本身的想法,有時候很難讓對方接受本身的想法,咱們也出現過這樣的問題,但通過討論,你們都獲得滿意的方案。spa
結對編程圖片:3d
如下爲本次做業的代碼:orm
form1blog
Form1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btn1_Click(object sender, EventArgs e) { Form2 form = new Form2(); form.Show(); } } }
界面:圖片
form2get
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 { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void ckbZheng_CheckedChanged(object sender, EventArgs e) { String getnum = txtNum.Text; int num = Convert.ToInt32(getnum); //輸入題目 String getmax = txtMax.Text; int minnum = Convert.ToInt32(getmax); //最小範圍設定 String getmin = txtMin.Text; int maxnum = Convert.ToInt32(getmin); //最大範圍設定 Random R = new Random(); int oper = 0; for (int i = 0; i < num; i++) { int num1, num2; num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); oper = R.Next(0, 3); switch (oper)//0-7分別表示加減乘除 { case 0: if (num2 >= 0) { listBox1.Items.Add(num1 + "+" + num2 + "="); } else { listBox1.Items.Add(num1 + "+" + "(" + num2 + ")" + "="); } break; case 1: if (num2 >= 0) { listBox1.Items.Add(num1 + "-" + num2 + "="); } else { listBox1.Items.Add(num1 + "-" + "(" + num2 + ")" + "="); } break; case 2: if (num2 >= 0) { listBox1.Items.Add(num1 + "*" + num2 + "="); } else { listBox1.Items.Add(num1 + "*" + "(" + num2 + ")" + "="); } break; case 3: if (num2 > 0) { listBox1.Items.Add(num1 + "/" + num2 + "="); } else if (num2 < 0) { listBox1.Items.Add(num1 + "/" + "(" + num2 + ")" + "="); } else { i++; } break; } } } private void ckbFeng_CheckedChanged(object sender, EventArgs e) { String getnum = txtNum.Text; int num = Convert.ToInt32(getnum); //輸入題目 String getmax = txtMax.Text; int minnum = Convert.ToInt32(getmax); //最小範圍設定 String getmin = txtMin.Text; int maxnum = Convert.ToInt32(getmin); //最大範圍設定 Random R = new Random(); int oper = 0; for (int i = 0; i < num; i++) { int num1, num2, num3, num4;//num1/num3第一個數;num2/num4第二個數 num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); num3 = R.Next(0, int.Parse(txtMax.Text)); num4 = R.Next(0, int.Parse(txtMax.Text)); oper = R.Next(0, 3); if (num3 != 0) { switch (oper)//0-7分別表示加減乘除 { case 0: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "+" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 1: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "-" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 2: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "*" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 3: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "/" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; } } else { i--; } } } private void ckbHun_CheckedChanged(object sender, EventArgs e) { String getnum = txtNum.Text; int num = Convert.ToInt32(getnum); //輸入題目 String getmax = txtMax.Text; int minnum = Convert.ToInt32(getmax); //最小範圍設定 String getmin = txtMin.Text; int maxnum = Convert.ToInt32(getmin); //最大範圍設定 Random R = new Random(); int oper = 0; for (int i = 0; i < num; i++) { int num1, num2, num3, num4; num1 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); num2 = R.Next(int.Parse(txtMin.Text), int.Parse(txtMax.Text)); num3 = R.Next(0, int.Parse(txtMax.Text)); num4 = R.Next(0, int.Parse(txtMax.Text)); oper = R.Next(0, 7); if (num3 != 0) { switch (oper)//0-7分別表示加減乘除 { case 0: if (num2 >= 0) { listBox1.Items.Add(num1 + "+" + num2 + "="); } else { listBox1.Items.Add(num1 + "+" + "(" + num2 + ")" + "="); } break; case 1: if (num2 >= 0) { listBox1.Items.Add(num1 + "-" + num2 + "="); } else { listBox1.Items.Add(num1 + "-" + "(" + num2 + ")" + "="); } break; case 2: if (num2 >= 0) { listBox1.Items.Add(num1 + "*" + num2 + "="); } else { listBox1.Items.Add(num1 + "*" + "(" + num2 + ")" + "="); } break; case 3: if (num2 > 0) { listBox1.Items.Add(num1 + "/" + num2 + "="); } else if (num2 < 0) { listBox1.Items.Add(num1 + "/" + "(" + num2 + ")" + "="); } else { i++; } break; case 4: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "+" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 5: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "-" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 6: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "*" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; case 7: if (num4 != 0) { listBox1.Items.Add("(" + num1 + "/" + num3 + ")" + "/" + "(" + num2 + "/" + num4 + ")" + "="); } else { i--; } break; } } else { i--; } } } private void button1_Click_1(object sender, EventArgs e) { txtNum.Text = ""; txtMin.Text = ""; txtMax.Text = ""; listBox1.Items.Clear(); } } }
界面:
運行結果: