题目要求 :http://www.cnblogs.com/gdfhp/p/5311937.html

结对同伴: 姓名:胡仕辉   学号:130201225   博客地址:http://www.cnblogs.com/hushihui666/

实现功能:

  1) 题目的数量(个人项目的要求)

  2) 数值的范围(个人项目的要求)

  3) 题目中最多几个运算符

  4) 题目中或运算过程中有无有分数(比如进行整数除法的时候不能除尽)

  5) 题目中是否有乘除法

  6) 题目中是否有括号

我负责程序构建的算法设计,胡仕辉同学负责窗体和代码生成

主要在之前完成的作业算法上进行改进,附上博客地址:http://www.cnblogs.com/SaltWu/p/5281184.html

合作优点在于可以互相讨论,每个人的想法不一样,有时候卡在一个问题上,同伴一个意见就能帮我拐弯。

合作时的照片:

      

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 新四则运算
{
public partial class 新四则运算 : Form
{ public 新四则运算()
{
InitializeComponent();
}
char[] ysf = { '+', '-', '*', '%'};
static int GetRandomSeed() //随机数种子,解决随机数一致问题
{
byte[] bytes = new byte[];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
return BitConverter.ToInt32(bytes, );
}
private void btn_1_Click(object sender, EventArgs e)
{
int n = Convert.ToInt32(this.tbox_n.Text); //获取生成题目数
int r = Convert.ToInt32(this.tbox_r.Text); //获取生成数范围
int ysf = Convert.ToInt32(this.cbox_ysf.Text.ToString()); //获取运算符个数
for(int i = ; i < n; i++) //生成n道题
{
if (ysf == ) //一个运算符
{
ysf1(r);
}
else if (ysf == ) // 两个运算符
{
ysf2(r);
}
else //三个运算符
{
ysf3(r);
}
input(" = ");
input("\n");
input("\n");
}
}
public void ysf1(int r) //一个运算符
{
if(cbox_fs.SelectedItem.ToString() == "是") //包含分数
{
Random rd = new Random(GetRandomSeed());
randnum1(r); //插入随机数,可以是分数
input_ysf(); //插入运算符
randnum1(r);
}
else
{
Random rd = new Random(GetRandomSeed());
randnum(r); //插入整数随机数
input_ysf();
randnum(r);
} }
public void ysf2(int r)
{
Random rd = new Random(GetRandomSeed());
int t = ;
t = rd.Next(); //随机运算符数量,1或2,对零时变量t随机,结果为0,跳至ysf1,结果为1则为ysf2
if (t == )
{
ysf1(r);
}
else
{ if(cbox_kh.SelectedItem.ToString() == "是") //包含括号
{
input_ysf2_kh(r);
}
else
{
input_ysf2(r);
} }
}
public void ysf3(int r)
{
Random rd = new Random(GetRandomSeed());
int t = ;
t = rd.Next(); //随机运算符数量,对零时变量t随机,结果为0,跳至ysf2,结果为1则为ysf3
if (t == )
{
ysf2(r);
}
else
{
if (cbox_kh.SelectedItem.ToString() == "是") //包含括号
{
int m = ;
m = rd.Next(); //对加括号的形式进行随机
if(m == )
{
input_ysf3_kh1(r); //括号形式1
}
else if(m == )
{
input_ysf3_kh2(r); //括号形式2
}
else
{
input_ysf3_kh3(r); //括号形式3
}
}
else
{
input_ysf3(r); //不含括号
}
} }
public void input_ysf()
{
input(" "); //运算符前后空格
Random rd = new Random(GetRandomSeed());
if (cbox_ccf.SelectedItem.ToString() == "是")
{
input(ysf[rd.Next()].ToString());//包含乘除法
}
else
{
input(ysf[rd.Next()].ToString());//不含乘除法
}
input(" ");
}
public void input_ysf2(int r)
{
if(cbox_fs.SelectedItem.ToString() == "是") //判断是否含分数
{
randnum1(r);
input_ysf();
randnum1(r);
input_ysf();
randnum1(r);
}
else
{
randnum(r);
input_ysf();
randnum(r);
input_ysf();
randnum(r);
} }
public void input_ysf2_kh(int r)
{
if (cbox_fs.SelectedItem.ToString() == "是") //含分数
{
input("(");
randnum1(r);
input_ysf();
randnum1(r);
input(")");
input_ysf();
randnum1(r);
}
else
{
input("(");
randnum(r);
input_ysf();
randnum(r);
input(")");
input_ysf();
randnum(r);
} }
public void input_ysf3(int r)
{
if (cbox_fs.SelectedItem.ToString() == "是") //含分数
{
randnum1(r);
input_ysf();
randnum1(r);
input_ysf();
randnum1(r);
input_ysf();
randnum1(r);
}
else
{
randnum(r);
input_ysf();
randnum(r);
input_ysf();
randnum(r);
input_ysf();
randnum(r);
} }
public void input_ysf3_kh1(int r) //带括号形式1
{
if (cbox_fs.SelectedItem.ToString() == "是")
{
input("[");
input("(");
randnum1(r);
input_ysf();
randnum1(r);
input(")");
input_ysf();
randnum1(r);
input("]");
input_ysf();
randnum1(r);
}
else
{
input("[");
input("(");
randnum(r);
input_ysf();
randnum(r);
input(")");
input_ysf();
randnum(r);
input("]");
input_ysf();
randnum(r);
} }
public void input_ysf3_kh2(int r) //带括号形式2
{
if (cbox_fs.SelectedItem.ToString() == "是")
{
randnum1(r);
input_ysf();
input("(");
randnum1(r);
input_ysf();
randnum1(r);
input(")");
input_ysf();
randnum1(r);
}
else
{
randnum(r);
input_ysf();
input("(");
randnum(r);
input_ysf();
randnum(r);
input(")");
input_ysf();
randnum(r);
} }
public void input_ysf3_kh3(int r) //带括号形式3
{
if (cbox_fs.SelectedItem.ToString() == "是")
{
input("(");
randnum1(r);
input_ysf();
randnum1(r);
input(")");
input_ysf();
input("(");
randnum1(r);
input_ysf();
randnum1(r);
input(")");
}
else
{
input("(");
randnum(r);
input_ysf();
randnum(r);
input(")");
input_ysf();
input("(");
randnum(r);
input_ysf();
randnum(r);
input(")");
} }
public void randnum(int r) //对数进行随机,只能是整数
{
Random rd = new Random(GetRandomSeed());
int num;
do
{
num = rd.Next(r + );
} while (num == ); // 随机整数不为 0 input(num.ToString()); }
public void randnum1(int r) //对数进行随机,可为分数
{
int t = ;
Random rd = new Random(GetRandomSeed());
t = rd.Next(); //对零时变量t随机,结果为0,这个数为整数,结果为1则为分数
if (t == )
{
int num;
do
{
num = rd.Next(r + );
} while (num == ); // 随机整数不为 0 input(num.ToString()); }
else
{
randnum2(r);
} } public void randnum2(int r) //分数随机
{
Random rd = new Random(GetRandomSeed());
int x, y; //x为分子,y为分母
do
{
x = rd.Next(r + );
} while (x == ); //分子不为0
do
{
y = rd.Next(r + );
} while (y == || y == x); //分母不为0,且不等于分子 if (x > y) //如果分子比分母大,则对调分子分母位置
{
int t = x;
x = y;
y = t;
}
input(x.ToString());
input("/");
input(y.ToString()); } public void input(string t)
{
tbox_shuchu.AppendText(t);
} private void btn_clc_Click(object sender, EventArgs e)
{
tbox_shuchu.Clear();
}
}
}

程序执行截图:

Homework_4 四则运算 - C#版的更多相关文章

  1. 结对编程项目——四则运算vs版

    结对编程项目--四则运算vs版 1)小伙伴信息:        学号:130201238 赵莹        博客地址:点我进入 小伙伴的博客 2)实现的功能: 实现带有用户界面的四则运算:将原只能在 ...

  2. 四则运算GUI版

    小学四则运算界面版 李永豪 201421123117 郑靖涛 201421123114 coding 地址:https://git.coding.net/ras/work2.git 一.题目描述 我们 ...

  3. 四则运算APP版

    (一)四则运算APP版 这这个Demo的目的就是强化一下本周学习的Android的Jetpack里的新内容,接下来我将通过这个Demo来展示我所学到的新知识. 先列出新学到的知识:ViewModel, ...

  4. 实验二 四则运算 完成版 ver.1

    package size; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JMenuBar; im ...

  5. 四则运算(Android)版

    实验题目: 将小学四则运算整合成网页版或者是Android版.实现有无余数,减法有无负数.... 设计思路: 由于学到的基础知识不足,只能设计简单的加减乘除,界面设计简单,代码量少,只是达到了入门级的 ...

  6. 结对编程1.四则运算GUI版

    201421123022 王若凡        201421123026  欧阳勇 coding详细代码 a.需求分析: 这个程序做成GUI(可以是Windows PC 上的,也可以是Mac.Linu ...

  7. 四则运算----C++版

    一.设计思想 因java中已做过,就是简单的将java中的语句调换为C++的语句. 二.代码 #include<iostream.h> #include<Stdlib.h> v ...

  8. 四则运算web版需求规格说明书

    目录 1引言... 4 1.1  目的... 4 1.2  背景... 4 1.3  术语... 4 1.4  预期读者与阅读建议... 5 1.5  参考资料... 6 1.6  需求描述约定... ...

  9. 四则运算安卓版ver.mk3

    在原有的基础上做了些许改动以及添加了一点小功能,以下是代码: package com.example.add; import java.io.File; import com.example.add. ...

随机推荐

  1. UINavigationController push时,页面卡顿

    1.A push B A.view.backgroundColor 与 B.view.backgroundColor 不一致. 2. AssistiveTouch打开 关闭则不会出现卡顿情况 3.增加 ...

  2. Spring Boot项目的打包和部署

    补充一点:搜索了下别人Spring Boot部署方案,大多都说:①packaging设为war:②要添加Spring Boot的tomcat依赖:③修改output路径,但是使用STS新建Spring ...

  3. scrot使用

    在Linux中安装Scrot 在 Debian,Ubuntu 或 Linux Mint 上安装Scrot: $ sudo apt-get install scrot 在 Fedora 上安装Scrot ...

  4. PMI列子1

    遍历得到PMI中,是注释类型的,你可以参考一下.int num_text, thetype, thesubtype;tag_t  draft_aid_tag = NULL_TAG;UF_UI_open ...

  5. Windows netstat 查看端口、进程占用

    目标:在Windows环境下,用netstat命令查看某个端口号是否占用,为哪个进程所占用. (1)查看该端口被那个PID所占用;方法一:有针对性的查看端口,在命令行下,使用命令netstat –an ...

  6. 也说说angularJs里的evalAsync

    虽说angular都快出2.0了,到了2.0这些东东都会被干掉.不过我们眼前的事还是要处理. $evalAsync和$timeout到底什么区别,网上说法很多,最近看到的是说在directive里就怎 ...

  7. Java打jar包详细教学

    如果我们需要将写好并测试OK的公共接口供多个项目使用,我们可以不用拷贝源代码,可以编译后打包成jar文件,这样会很方便许多,修改的话也方便,直接修改源代码打一个新jar包替换即可,下面是打包的详细教程 ...

  8. zabbix微信告警(虚拟机脚本测试成功,zabbix上收不到信息)

    前言: 使用zabbix直接运行脚本又可以正常接收.但是登录zabbix  web界面,测试!  动作显示已送达,但是微信并没有收到信息! 解决: 添加脚本参数,因为不添加脚本参数,调用不了你这个脚本 ...

  9. 数位DP

    题意:(hdu 4734) 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目 ...

  10. SSH项目(struts+spring+hibernate)搭建_代码简化

    在上篇讲到SSH框架的搭建后,为了有利于随时能熟练的把一个SSH的项目快速的搭建起来,我又进一步对其了解学习,对代码进行了简化,大家相互讨论学习. 为什么要简化:  如果要做一个大项目,假设项目的ac ...