1 Star 0 Fork 0

张颖威 / learngit

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
szys.txt 16.65 KB
Copy Edit Web IDE Raw Blame History
MOLEkiss authored 2020-02-24 14:51 . szys
//
// main.cpp
// 四则运算
//
// Created by MOLEkiss on 2020/2/23.
// Copyright © 2020 MOLEkiss. All rights reserved.
//
#include<iostream>
using namespace std;
#include<time.h>
#include<string>
int main()
{
int count=0 ;
srand(time(NULL));//用系统当前时间设置rand()随机序列种子,保证每次运行随机序列不一样
char ch;
while(count<30)
{
cout<<"选择年级一年级(输入'1')或二年级(输入'2')或三年级(输入'3')或四年级(输入'4')或五年级(输入'5')"<<endl;
cin>>ch;
if(ch=='1')
{cout<<"选择难易度,选择易(输入'6'),选择中(输入'7'),选择难(输入'8')"<<endl;
cin>>ch;
if(ch=='6')
{cout<<"开始产生一年级四则运算'易'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;
}
if(ch=='7'){{cout<<"开始产生一年级四则运算'中'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;}
}
if(ch=='8'){{cout<<"开始产生一年级四则运算'难'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;}
}}
if(ch=='2')
{cout<<"选择难易度,选择易(输入'6'),选择中(输入'7'),选择难(输入'8')"<<endl;
cin>>ch;
if(ch=='6')
{cout<<"开始产生二年级四则运算'易'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;
}
if(ch=='7'){{cout<<"开始产生二年级四则运算'中'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;}
}
if(ch=='8'){{cout<<"开始产生二年级四则运算'难'难度:"<<endl;
cout<<"选择做整数运算(输入'a')"<<endl;}
}}
if(ch=='3')
{cout<<"选择难易度,选择易(输入'6'),选择中(输入'7'),选择难(输入'8')"<<endl;
cin>>ch;
if(ch=='6')
{cout<<"开始产生二年级四则运算'易'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;
}
if(ch=='7'){{cout<<"开始产生二年级四则运算'中'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}
}
if(ch=='8'){{cout<<"开始产生二年级四则运算'难'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}}}
if(ch=='4')
{cout<<"选择难易度,选择易(输入'6'),选择中(输入'7'),选择难(输入'8')"<<endl;
cin>>ch;
if(ch=='6')
{cout<<"开始产生二年级四则运算'易'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;
}
if(ch=='7'){{cout<<"开始产生二年级四则运算'中'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}
}
if(ch=='8'){{cout<<"开始产生二年级四则运算'难'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}}}
if(ch=='5')
{cout<<"选择难易度,选择易(输入'6'),选择中(输入'7'),选择难(输入'8')"<<endl;
cin>>ch;
if(ch=='6')
{cout<<"开始产生二年级四则运算'易'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;
}
if(ch=='7'){{cout<<"开始产生二年级四则运算'中'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}
}
if(ch=='8'){{cout<<"开始产生二年级四则运算'难'难度:"<<endl;
cout<<"选择做整数运算(输入'a')或真分数运算(输入'b')"<<endl;}}}
//产生整数的运算
cin>>ch;
if(ch=='a')
{cout<<"开始产生四则运算:"<<endl;
int a0[1000],b0[1000],c0[1000],a1[1000],b1[1000],c1[1000],a2[1000],b2[1000],c2[1000],a3[1000],b3[1000],c3[1000],C[1000],a,b,c;
int i,j,A0,A1,A2,A3,B0,B1,B2,B3;
int num,line,k;
int min,max,m;
int CC,FS,YS;
k=0;
A0=0;A1=0;A2=0;A3=0;
B0=0;B1=0;B2=0;B3=0;
cout<<"*************四则运算1.0*************"<<endl;
cout<<"请依次输入输出算式数量和每行显示数量:"<<endl;
cin>>num>>line;
cout<<"请问是否要有乘除法?有请输入\"1\",无请输入\"0\""<<endl;
cin>>CC;
while(1) //判断输入是否合法
{
if(CC != 1&&CC != 0)
{
cout<<"输入不合法,请重新输入\"1\"或\"0\":";
cin>>CC;
}
else
break;
}
cout<<"请问是否要加减结果有负数?有请输入\"1\",无请输入\"0\""<<endl;
cin>>FS;
while(1) //判断输入是否合法
{
if(FS != 1&&FS != 0)
{
cout<<"输入不合法,请重新输入\"1\"或\"0\":";
cin>>FS;
}
else
break;
}
cout<<"请问是否要除法结果有余数?有请输入\"1\",无请输入\"0\""<<endl;
cin>>YS;
while(1) //判断输入是否合法
{
if(YS != 1&&YS != 0)
{
cout<<"输入不合法,请重新输入\"1\"或\"0\":";
cin>>YS;
}
else
break;
}
cout<<"请输入两个值确定算式中a,b的取值范围(请保证前一个值小于后一个值):"<<endl;
cin>>min>>max;
while(1) //判断输入是否合法
{
if(min>=max)
{
cout<<"输入不合法,请重新输入:";
cin>>min>>max;
}
else
break;
}
m=max-min+1;
for(i=0;i<1000;i++)
{
a0[i]=0;b0[i]=0;
a1[i]=0;b1[i]=0;
a2[i]=0;b2[i]=0;
a3[i]=0;b3[i]=0;
}
for(i=0;;i++)
{
a=min+rand()%m;
b=min+rand()%m;
c=rand()%4;
if(CC==0) //如果CC=0,去除c=2,3的情况
{
if(c==2||c==3)
continue;
}
if(FS==0) //如果FS=0,去除c=0,1下结果小于0的情况
{
if(c==0)
{
if(a+b<0)
continue;
}
else if(c==1)
{
if(a-b<0)
continue;
}
}
if(YS==0) //如果YS=0,且是除法,去除a,b相除有余数的情况
{
if(c==3)
if(0 != a%b)
continue;
}
//将算式分为加、减、乘、除四组
if(c==0) //加法
{
for(j=0;j<=A0;j++)
{
if(a==a0[j]&&b==b0[j])
{
B0++;break;
}
}
if(B0>0)
{
B0=0;continue;
}
else
{
a0[A0]=a;
b0[A0]=b;
c0[A0]=a+b;
A0++;
}
}
else if(c==1) //减法
{
for(j=0;j<=A1;j++)
{
if(a==a1[j]&&b==b1[j])
{
B1++;break;
}
}
if(B1>0)
{
B1=0;continue;
}
else
{
a1[A1]=a;
b1[A1]=b;
c1[A1]=a+b;
A1++;
}
}
else if(c==2) //乘法
{
for(j=0;j<=A2;j++)
{
if(a==a2[j]&&b==b2[j])
{
B2++;break;
}
}
if(B2>0)
{
B2=0;continue;
}
else
{
a2[A2]=a;
b2[A2]=b;
c2[A2]=a+b;
A2++;
}
}
else //除法
{
if(b==0)
continue;
for(j=0;j<=A3;j++)
{
if(a==a3[j]&&b==b3[j])
{
B3++;break;
}
}
if(B3>0)
{
B3=0;continue;
}
else
{
a3[A3]=a;
b3[A3]=b;
c3[A3]=a+b;
A3++;
}
}
if(num==A0+A1+A2+A3) //限制算式数量
break;
}
//输出
for(i=0;i<A0;i++) // +
{
k++;
if(a0[i]<0)
cout<<"("<<a0[i]<<")";
else
cout<<a0[i]<<" ";
cout<<"+";
if(b0[i]<0)
cout<<"("<<b0[i]<<")";
else
cout<<" "<<b0[i]<<" ";
cout<<"=";
if(k%line==0)
cout<<endl;
else
cout<<"\t";
}
for(i=0;i<A1;i++) // -
{
k++;
if(a1[i]<0)
cout<<"("<<a1[i]<<")";
else
cout<<a1[i]<<" ";
cout<<"-";
if(b1[i]<0)
cout<<"("<<b1[i]<<")";
else
cout<<" "<<b1[i]<<" ";
cout<<"=";
if(k%line==0)
cout<<endl;
else
cout<<"\t";
}
for(i=0;i<A2;i++) // *
{
k++;
if(a2[i]<0)
cout<<"("<<a2[i]<<")";
else
cout<<a2[i]<<" ";
cout<<"*";
if(b2[i]<0)
cout<<"("<<b2[i]<<")";
else
cout<<" "<<b2[i]<<" ";
cout<<"=";
if(k%line==0)
cout<<endl;
else
cout<<"\t";
}
for(i=0;i<A3;i++) // /
{
k++;
if(a3[i]<0)
cout<<"("<<a3[i]<<")";
else
cout<<a3[i]<<" ";
cout<<"/";
if(b3[i]<0)
cout<<"("<<b3[i]<<")";
else
cout<<" "<<b3[i]<<" ";
cout<<"=";
if(k%line==0)
cout<<endl;
else
cout<<"\t";
}
cout<<"请在此输入各式的结果:"<<endl;
for(i=0;i<num;i++)
cin>>C[i];
int t=0,corr=0;
//判断输入结果的对错
for(i=0;i<A0;i++)
{
if(c0[i]==C[t])
{t++;corr++;}
else
{
t++;
cout<<"第"<<t<<"题答错!"<<endl;
}
}
for(i=0;i<A1;i++)
{
if(c1[i]==C[t])
{t++;corr++;}
else
{
t++;
cout<<"第"<<t<<"题答错!"<<endl;
}
}
for(i=0;i<A2;i++)
{
if(c2[i]==C[t])
{t++;corr++;}
else
{
t++;
cout<<"第"<<t<<"题答错!"<<endl;
}
}
for(i=0;i<A3;i++)
{
if(c3[i]==C[t])
{t++;corr++;}
else
{
t++;
cout<<"第"<<t<<"题答错!"<<endl;
}
}
if(line==corr)
cout<<"恭喜你都答对了!!!!!!"<<endl;
}
//产生真分数的运算
if(ch=='b')
{
int m1=0,m2=0,n1=0,n2=0;
m1=0+rand()%100;
m2=0+rand()%100;
//判断产生的真分数正确性
while(m1<m2)
{
m1=0+rand()%100;
m2=0+rand()%100;
}
n1=0+rand()%100;
n2=0+rand()%100;
//判断产生的真分数正确性
while(n1<n2)
{
n1=0+rand()%100;
n2=0+rand()%100;
}
string fuhao[4]={"+","-","*","/"};
int fushu=((0+rand()%4)+4)%4;
//cout<<fushu<<endl;
if(fushu==0)
//输出算术式
for(fushu=0;fushu<=100;fushu++)
//判断shu2是否为0和是否为除法 若为则重新生成
//随机产生的符号
switch(fushu)
{
case 0:cout<<"("<<m2<<"/"<<m1<<")"<<fuhao[fushu]<<"("<<n2<<"/"<<n1<<")"<<endl;break;
case 1:cout<<"("<<m2<<"/"<<m1<<")"<<fuhao[fushu]<<"("<<n2<<"/"<<n1<<")"<<endl;break;
case 2:cout<<"("<<m2<<"/"<<m1<<")"<<fuhao[fushu]<<"("<<n2<<"/"<<n1<<")"<<endl;break;
case 3:cout<<"("<<m2<<"/"<<m1<<")"<<fuhao[fushu]<<"("<<n2<<"/"<<n1<<")"<<endl;break;
}
}
count++;
}
}

Comment ( 0 )

Sign in for post a comment

C++
1
https://gitee.com/zhang_ying_wei/learngit.git
git@gitee.com:zhang_ying_wei/learngit.git
zhang_ying_wei
learngit
learngit
master

Search