《四则运算》

(1)代码

//四则运算

#include<iostream>
using namespace std;

int main()
{
int a,b,c,d,e,f,g,h,i,j,k,l[1000],m,n[1000],o;

cout << "请输入所需要的题目的数目:";
cin >> a;
cout << "请选择打印的每页有多少题:";
cin >> f;
cout << "请选择是否支持负数(1.支持 2.不支持):";
cin >> g;
if (g == 1)
{
do
{
cout << "请输入数值范围(第一个数小于第二个数):";
cin >> b >> c;
} while (b >= 0);
}
if (g == 2)
{
cout << "请输入数值范围(第一个数小于第二个数):";
cin >> b >> c;
}
cout << "请选择是否有乘除法(1.有 2.没有):";
cin >> d;
if (d == 1)
{
cout << "请选择除法有无余数(1.有 2.没有):";
cin >> e;
for (m = 0; m < a; m++)
{
l[m] = rand() % (c - b + 1) + b;
n[m] = rand() % (c - b + 1) + b;
h = rand() % 4;
if (e == 1)
{
if (h == 0)
{
if (n[m] >= 0)
{
cout << l[m] << "+" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "+" << "("<<n[m]<<")" << "=" << endl;
}
}
if (h == 1)
{
if (n[m] >= 0)
{
cout << l[m] << "-" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "-" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 2)
{
if (n[m] >= 0)
{
cout << l[m] << "*" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "*" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 3)
{
if (n[m] == 0)
{
m = m - 1;
}
else
{
if (n[m] >= 0)
{
cout << l[m] << "/" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "/" << "(" << n[m] << ")" << "=" << endl;
}
}
}
}
if (e == 2)
{
if (n[m] <= 0)
{
n[m] = -n[m];
}
if (l[m] <= 0)
{
l[m] = -l[m];
}
if (l[m] % n[m] != 0)
{
m = m - 1;
}
if (l[m] % n[m] == 0)
{
if (h == 0)
{
if (n[m] >= 0)
{
cout << l[m] << "+" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "+" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 1)
{
if (n[m] >= 0)
{
cout << l[m] << "-" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "-" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 2)
{
if (n[m] >= 0)
{
cout << l[m] << "*" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "*" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 3)
{
if (n[m] >= 0)
{
cout << l[m] << "/" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "/" << "(" << n[m] << ")" << "=" << endl;
}
}
}
}
if ((m + 1) % f == 0)
{
cout << endl;
cout << endl;
}
}
}
if (d == 2)
{
cout << "请选择除法有无余数(1.有 2.没有):";
cin >> e;
for (m = 0; m < a; m++)
{
l[m] = rand() % (c - b + 1) + b;
n[m] = rand() % (c - b + 1) + b;
h = rand() % 2;
if (e == 1)
{
if (h == 0)
{
if (n[m] >= 0)
{
cout << l[m] << "+" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "+" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 1)
{
if (n[m] >= 0)
{
cout << l[m] << "-" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "-" << "(" << n[m] << ")" << "=" << endl;
}
}
}
if (e == 2)
{
if (l[m] % n[m] != 0)
{
m = m - 1;
}
if (l[m] % n[m] == 0)
{
if (h == 0)
{
if (n[m] >= 0)
{
cout << l[m] << "+" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "+" << "(" << n[m] << ")" << "=" << endl;
}
}
if (h == 1)
{
if (n[m] >= 0)
{
cout << l[m] << "-" << n[m] << "=" << endl;
}
if (n[m] < 0)
{
cout << l[m] << "-" << "(" << n[m] << ")" << "=" << endl;
}
}
}
}
if ((m + 1) % f == 0)
{
cout << endl;
cout << endl;
}
}
}
}

(2)截图:

(3)开发过程

先对各个条件进行判断,再根据对各个条件的选择进行进一步的编写,将本程序分成不同的小模块

(4)

原文地址:https://www.cnblogs.com/1305yyf/p/4348514.html