四则运算加强版
Posted 野野
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四则运算加强版相关的知识,希望对你有一定的参考价值。
//3.3.2016 tangyeye
#include<stdio.h>
#include<iostream>
#include<time.h>
#include<fstream>
#include<ostream>
#include<string>
using namespace std;
#define MAX N
int a(void)
{
srand((unsigned)time(NULL));
int a,b,c,d,e,i,n,x;
int N;
cout<<"请输入题目的数量!"<<endl;
cin>>i;
cout<<"请输入多少数以内的四则运算"<<endl;
cin>>N;
cout<<"是否有乘除号?(1是,0否)"<<endl;
cin>>x;
cout<<"打印的四则运算结果为非负数,且除法运算无余数"<<endl;
if(x==0)
{
for(int j=0;j<i;j++)
{
a=rand()%MAX;
b=rand()%MAX;
c=rand()%2+1;
switch(c){
case 1: cout<<a<<"+"<<b<<endl;
break;
case 2: if(a>=b) {cout<<a<<"-"<<b<<endl;} else{cout<<b<<"-"<<a<<endl;};
break;
}
}}
else
{
for(int j=0;j<i;j++)
{
a=rand()%MAX;
b=rand()%MAX;
c=rand()%4+1;
switch(c)
{
case 1: cout<<a<<"+"<<b<<endl;
break;
case 2:if(a>=b) {cout<<a<<"-"<<b<<endl;} else{cout<<b<<"-"<<a<<endl;}
break;
case 3: cout<<a<<"*"<<b<<endl;
break;
case 4:if(a%b==0) {cout<<a<<"/"<<b<<endl;}else{cout<<a<<"*"<<b<<endl;}
break;
}
}
return 0;
}
}
int b(void)
{
srand((unsigned)time(NULL));
int a,b,c,d,e,i,n,x;
int N;
cout<<"请输入题目的数量!"<<endl;
cin>>i;
cout<<"请输入多少数以内的四则运算"<<endl;
cin>>N;
cout<<"是否有乘除号?(1是,0否)"<<endl;
cin>>x;
cout<<"打印的四则运算结果为非负数,且除法运算无余数"<<endl;
ofstream fout("D:\\1.txt",ios::binary);
if(!fout)
{
cerr<<"open wrong!"<<endl;
}
if(x==0)
{
for(int j=0;j<i;j++)
{
a=rand()%MAX;
b=rand()%MAX;
c=rand()%2+1;
switch(c){
case 1: fout<<a<<"+"<<b<<endl;
break;
case 2: if(a>=b) {fout<<a<<"-"<<b<<endl;} else{fout<<b<<"-"<<a<<endl;};
break;
}
}}
else
{
for(int j=0;j<i;j++)
{
a=rand()%MAX;
b=rand()%MAX;
c=rand()%4+1;
switch(c)
{
case 1: fout<<a<<"+"<<b<<endl;
break;
case 2:if(a>=b) {fout<<a<<"-"<<b<<endl;} else{fout<<b<<"-"<<a<<endl;}
break;
case 3: fout<<a<<"*"<<b<<endl;
break;
case 4:if(a%b==0) {fout<<a<<"/"<<b<<endl;}else{fout<<a<<"*"<<b<<endl;}
break;
}
}
return 0;
}
}
int q(void)
{
srand((unsigned)time(NULL));
int i,x,a,b,c,d,n3,c2;
char a1;
int N;
cout<<"请输入参与数目!(3<=n<10)"<<endl;
cin>>n3;
cout<<"请输入题目的数量!"<<endl;
cin>>i;
cout<<"请输入多少数以内的四则运算"<<endl;
cin>>N;
cout<<"是否有乘除号?(1是,0否)"<<endl;
cin>>x;
cout<<"打印的四则运算结果为非负数,且除法运算无余数"<<endl;
if(x==0)
{
for(int j=0;j<i;j++)
{
a=rand()%MAX;
b=rand()%MAX;
d=rand()%MAX;
c=rand()%4+1;
switch(c)
{
case 1:a1=‘+‘;
break;
case 2:a1=‘-‘;
break;
case 3:a1=‘*‘;
break;
case 4:a1=‘/‘;
break;
}
if(n3=3)
{
c2=rand()%3+1;
switch(c2)
{
case 1:cout<<a<<a1<<b<<endl;
break;
case 2:cout<<"("<<a<<a1<<b<<")"<<b<<endl;
break;
case 3:cout<<a<<"("<<a<<a1<<b<<")"<<endl;
break;
}
}
}}
else
{
for(int j=0;j<i;j++)
{
}
}
return 0;
}
int main(void)
{
int n,n1,n3;
cout<<"是否有括号?(1有,0否)"<<endl;
cin>>n1;
if(n1=1)
{
{
q();
}
}
if(n1=0)
{
cout<<"是否打印?(1存入文档,0否)"<<endl;
cin>>n;
if(n==1)
{
b();
}
else if(n==0)
{
a();
}
else
{
cout<<"error input!"<<endl;
}
}
else
{
cout<<"error input!"<<endl;
}
}
以上是关于四则运算加强版的主要内容,如果未能解决你的问题,请参考以下文章