1.同伴信息
王硕朋,计科13-1,学号:130201124
2.基本功能
这次作业是四则运算,就是加减乘除之间运算,通俗简单。
3.程序截图
1)窗体布局截图
2)程序运行截图
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 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; //分数除法
}
}
}
}
}5.总结通过这几个学时的学习,以及老师和助教仔细教导,我技术突飞猛进,感谢老师助教和同学指导!
时间: 2024-10-21 03:56:57