结对编程项目--四则运算
1.同伴信息:
班级:13级计科一班
姓名:徐小康
学号:130201138
2.基本功能
本次作业是在上次作业的基础之上完成的,也是上次作业的升华。在建立的窗体中你自己可以确定你想出题的数目,并且你也可以确定数值的范围。出题的范围可以是加,减,乘,除任意的,可以是整数也可以是分数。
3.作业总结
本次作业对我来说还是有一定的难度的,作业也有一些功能没有完成比如只能抽出题目,但是没有答案的显示。希望经过这个学期的学习我可以更加的进步,并且更好的完成接下来的每一次作业。
4.程序截图
1)窗体布局截图
2)程序运行截图
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Integerdivide()
{
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax); //最小范围设定
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin); //最大范围设定
Random R = new Random(); //取随机数
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
if (den2 != 0)
list.Items.Add(den1 + "/" + "(" + den2 + ")" + "=");
else
{
list.Items.Add(den2 + "/" + "(" + den1 + ")" + "=");
}
}
public void Fractionadd()
{
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax);
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin);
Random R = new Random();
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
if (den1 != 0)
{
if (den2 != 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "+" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "+" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
else
{
if (den2 != 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "+" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "+" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
}
public void Fractiondelete()
{
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax);
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin);
Random R = new Random();
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
if (den1 != 0)
{
if (den2 != 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "-" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "-" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
else
{
if (den2 != 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "-" + "(" + num2 + "-" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "-" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
}
public void Fractionmultiply()
{
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax);
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin);
Random R = new Random();
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
if (den1 != 0)
{
if (den2 != 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "*" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "*" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
else
{
if (den2 != 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "*" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "*" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
}
public void Fractiondivide()
{
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax);
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin);
Random R = new Random();
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
if (den1 != 0)
{
if (den2 != 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "/" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + num1 + "/" + den1 + ")" + "/" + "(" + den2 + "/" + num2 + ")" + "=");//换
}
}
else
{
if (den2 != 0)
{
list.Items.Add("(" + den1 + "/" + num1 + ")" + "/" + "(" + num2 + "/" + den2 + ")" + "=");
}
else if (den2 == 0)
{
list.Items.Add("(" + den1 + " / " + num1 + ")" + "/" + "(" + den2 + "/" + num2 + ")" + "=");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String getnum = textIn.Text;
int num = Convert.ToInt32(getnum); //输入题目数
String getmax = textMin.Text;
int minnum = Convert.ToInt32(getmax); //最小数设定
String getmin = textMax.Text;
int maxnum = Convert.ToInt32(getmin); //最大数设定
int i;
Random R = new Random();
int import = 0;
for (i = 0; i < num; i++)
{
int den1, den2, num1, num2;
den1 = R.Next(minnum, maxnum);
num1 = R.Next(minnum, den1);
den2 = R.Next(minnum, maxnum);
num2 = R.Next(minnum, den2);
import = R.Next(0, 8);
switch (import)
{
case 0: list.Items.Add(den1 + "+" + "(" + den2 + ")" + "="); break;
case 1: list.Items.Add(den1 + "-" + "(" + den2 + ")" + "="); break;
case 2: list.Items.Add(den1 + "*" + "(" + den2 + ")" + "="); break;
case 3: Integerdivide(); break; //整数除法
case 4: Fractionadd(); break; //分数加法
case 5: Fractiondelete(); break; //分数减法
case 6: Fractionmultiply(); break;//分数乘法
case 7: Fractiondivide(); break; //分数除法
}
}
}
}
}