码迷,mamicode.com
首页 > 其他好文 > 详细

结对编程项目---四则运算

时间:2016-04-07 06:57:31      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

同组人:胡媛http://www.cnblogs.com/hy0926/

基本功能:

1) 实现一个带有用户界面的四则运算。

2) 生成的题目不能重复。

3) 支持负数。

需要支持的基本设定参数

1) 题目的数量

2) 数值的范围

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

4) 题目中或运算过程中有无有分数

5) 题目中是否有乘除法

6) 题目中是否有括号

7) 题目中或运算过程中有无负数

工作分配:

两人共同参与并一起完成

代码:

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;
using caculate.math.Biz;

namespace 四则运算
{
public partial class Form1 : Form
{
//加减运算
private String[] strs1 = new String[] { "+", "-", };
private Random r10 = new Random();
//乘除运算
private String[] strs2 = new String[] { "*","/"};
private Random r11 = new Random();
//混合运算
private String[] strs3 = new String[] { "+","-","*", "/" };
private Random r12 = new Random();
public Form1()
{
InitializeComponent();
}
private string GetOperationString(Operation operation)
{
switch (operation)
{
case Operation.Add:
return "+";
case Operation.Minus:
return "-";
case Operation.Multiply:
return "×";
case Operation.Divide:
return "÷";
}
return "+";
}
private TextBox GetTextBox(int index, int num)
{


foreach (Control col in this.Controls)
{
if (col.Name == "txtNUM" + index + num)
{
return (TextBox)col;
}

}
return null;
int main()
{
int count=0 ;
srand(time(NULL));//用系统当前时间设置rand()随机序列种子,保证每次运行随机序列不一样 
char ch;
while(count<30)
{
cout<<"选择做整数运算(输入‘a‘)或真分数运算(输入‘b‘)"<<endl;
//产生整数的运算
cin>>ch;
if(ch==a)
{cout<<"开始产生四则运算:"<<endl;
int shu1=0,shu2=0;
//随机数产生0-100
//shu1=srand(1000);


shu1=0+rand()%100;
shu2=0+rand()%100;

int sum=0;
int fushu=0;
string fuhao[4]={"+","-","*","/"};
fushu=((0+rand()%4)+4)%4;
//cout<<fushu<<endl;

//判断shu2是否为0和是否为除法 若为则重新生成
while(shu2==0&fushu==3)
{
shu2=0+rand()%100;
}
//随机产生的符号
switch(fushu)
{
case 0:cout<<shu1<<fuhao[fushu]<<shu2<<endl;break;
case 1:cout<<shu1<<fuhao[fushu]<<shu2<<endl;break;
case 2:cout<<shu1<<fuhao[fushu]<<shu2<<endl;break;
case 3:cout<<shu1<<fuhao[fushu]<<shu2<<endl;break;
}
}

//产生真分数的运算
if(ch==b)
{
int zhenfens1_m=0,zhenfens1_z=0,zhenfens2_m=0,zhenfens2_z=0;

zhenfens1_m=0+rand()%100;
zhenfens1_z=0+rand()%100;

//判断产生的真分数正确性
while(zhenfens1_m<zhenfens1_z)
{
zhenfens1_m=0+rand()%100;
zhenfens1_z=0+rand()%100;
}

zhenfens2_m=0+rand()%100;
zhenfens2_z=0+rand()%100;

//判断产生的真分数正确性
while(zhenfens2_m<zhenfens2_z)
{
zhenfens2_m=0+rand()%100;
zhenfens2_z=0+rand()%100;
}

string fuhao[4]={"+","-","*","/"};
int fushu=((0+rand()%4)+4)%4;
//cout<<fushu<<endl;

//判断shu2是否为0和是否为除法 若为则重新生成
//随机产生的符号
switch(fushu)
{
case 0:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<endl;break;
case 1:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<endl;break;
case 2:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<endl;break;
case 3:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<endl;break;
}

}
count++;
}
}

 

 总结:由于基础不好,我与同组胡媛上网查阅资料以及询问同学。还是艰难的把这个做出来了。感觉到自己的不足和与别人的差距。

通过这次锻炼也明白应该认真做好每件事这样才能对自己的锻炼有很大的帮助

 

截图:技术分享技术分享

 

技术分享

结对编程项目---四则运算

标签:

原文地址:http://www.cnblogs.com/zzk0926/p/5361929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!