#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<stdio.h>
#include<Windows.h>
#include<iomanip>
#define pi_ 3.1415926535898
using namespace std;
float add(float jia1, float jia2)//加法函数
{
float jiaguo = jia1 + jia2;
return jiaguo;
}
float subtract(float jian1, float jian2)//减法函数
{
float jianguo = jian1 - jian2;
return jianguo;
}
float ride(float cheng1, float cheng2)//乘法函数
{
float jianguo = cheng1 * cheng2;
return jianguo;
}
float getridof(float chu1, float chu2)//除法函数
{
float jianguo = chu1 / chu2;
return jianguo;
}
int main()
{
time_t begin, end;
double ret;
begin = clock();
long float jieguo = 0, jieguo1 = 0, jieguo2 = 0,jieguo3 = 0,chufa1 = 1, chufa2 = 1, jiafa1 = 0, jiafa2 = 0, jianfa1 = 0, jianfa2 = 0, chengfa1 = 0, chengfa2 = 0,radius = 0,area = 0;
long int chengchuxuanze1 = 0, jieshuyu = 0,zhi = 0,jiao = 0,ji = 0,tu = 0;
int xuanshizi = 0;
int xuanze = 0;
cout << "欢迎使用此程序\n输入1为新版使用函数计算器 可以计算小数且更快的计算速度\n输入2为第一版计算器使用运算法计算器" << endl;
cin >> xuanze;
system("cls");
switch (xuanze)
{
case 1:
L01:cout << "----------------计算器----------------------\t" << endl;
cout << "请输入运算的类型:\n1,加法\t最大支持8字节数据\n2,减法\t最大支持8字节数据\n3,乘除\t最大支持8字节数据\n4,九 九 乘 法 表\n5,鸡兔同笼题运算\t最大支持8字节数据\n6,圆面积计算\t最大支持8字节数据" << endl;
cout << "----------输入运算类型前的数字--------------\t" << endl;
cin >> xuanshizi;//用户输入选择
system("cls");
switch (xuanshizi)
{
case 1://加
cout << "--------------------加法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> jiafa1;
cout << "您输入的数字为:" << jiafa1 << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> jiafa2;
cout << "您输入的数字为:" << jiafa2 << endl;
jieguo1 = add(jiafa1, jiafa2);//运算结果
cout << "--------------------------------------------\t" << endl;
cout << jiafa1 << " 加 " << jiafa2 << " 等于 " << setprecision(10) << jieguo1 << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 2://减
cout << "--------------------减法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> jianfa1;
cout << "您输入的数字为:" << jianfa1 << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> jianfa2;
cout << "您输入的数字为:" << jianfa2 << endl;
jieguo = subtract(jianfa1, jianfa2); //运算结果
cout << "--------------------------------------------\t" << endl;
cout << jianfa1 << " 减 " << jianfa2 << " 等于 " << setprecision(10) << jieguo << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 4://乘法口诀表
cout << "-----------------乘法口诀表-----------------\t" << endl;
for (int n9 = 1; n9 <= 9; n9++)
{
for (int m9 = 1; m9 <= n9; m9++)
{
cout << m9 << "*" << n9 << "=" << m9 * n9 << "\t";
}
cout << endl;
}
cout << "--------------------------------------------\t" << endl;
break;
case 5://鸡兔同笼
cout << "-----------------鸡兔同笼题-----------------\t" << endl;
cout << "鸡和兔一共有多少只" << endl;
cin >> zhi;
cout << "鸡和兔一共有多少脚" << endl;
cin >> jiao;
tu = (jiao - (2 * zhi));
tu = tu / 2;
ji = zhi - tu;
cout << "鸡有:" << ji << "只\n" << "兔有:" << tu << "只" << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;
case 6:
cout << "-----------------圆面积计算-----------------\t" << endl;
cout << "请输入圆的半径:" << endl;
cin >> radius;
area = radius * radius * pi_;
cout << "圆的半径是:" << setprecision(15) << radius << "圆的面积是:" << area << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;
case 3://乘除选择
cout << "------------------乘除选择------------------\t" << endl;
cout << "乘法还是除法?" << endl;
cout << "1,乘法" << endl;
cout << "2,除法" << endl;
cout << "--------------------------------------------\t" << endl;
cin >> chengchuxuanze1;
system("cls");//清空上面内容
switch (chengchuxuanze1)
{
case 1://乘
cout << "------------------乘法----------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> chengfa1;
cout << "您输入的数字为:" << chengfa1 << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> chengfa2;
cout << "您输入的数字为:" << chengfa2 << endl;
jieguo2 = ride(chengfa1,chengfa2);//运算结果
cout << "--------------------------------------------\t" << endl;
cout << chengfa1 << " 乘 " << chengfa2 << " 等于 " << setprecision(10) << jieguo2 << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 2://除
cout << "--------------------除法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> chufa1;
cout << "您输入的数字为:" << chufa1 << endl;
L02:cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> chufa2;
cout << "您输入的数字为:" << chufa2 << endl;
cout << "--------------------------------------------\t" << endl;
if (chufa2>0)
{
jieguo3 = getridof(chufa1,chufa2);//运算结果
cout << chufa1 << " 除 " << chufa2 << " 等于 " << setprecision(10) << jieguo3 << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
}
else
{
cout << "第二个数字不能小于等于0!" << endl;
goto L02;
}
break;
default:
break;
}
default:
break;
}
cout << "1,重新开始 2,退出程序" << endl;//选择继续运行还是退出
cin >> jieshuyu;
switch (jieshuyu)
{
case 1:
system("cls");//清空并重新运行l1内容
goto L01;
case 2:
cout << "-----------------回车退出-------------------\t" << endl;
end = clock();
ret = double(end - begin) / CLOCKS_PER_SEC;
cout << endl;
cout << "程序运行时间: " << ret << "秒" << endl;
system("pause");//退出程序
default:
break;
}
case 2: L1:cout << "----------------计算器----------------------\t" << endl;
cout << "请输入运算的类型:\n1,加法 最大支持-+2147483647\n2,减法 最大支持-+2147483647\n3,乘除 最大支持-+2147483647\n4,九 九 乘 法 表\n5,鸡兔同笼题运算\n6,圆面积计算" << endl;
cout << "----------输入运算类型前的数字--------------\t" << endl;
int select = 0;//创建变量选择
int chengchu = 0;//乘除的变量选择
int jieshu = 0;
cin >> select;//用户输入选择
int d = 0, e = 0, f = 0, a = 0, b = 0, c = 0, g = 0, h = 0, i = 0;//加减乘
float l = 0, k = 1, n = 1;//除
system("cls");
switch (select)
{
case 1://加
cout << "--------------------加法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> d;
cout << "您输入的数字为:" << d << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> e;
cout << "您输入的数字为:" << e << endl;
f = d + e;//运算结果
cout << "--------------------------------------------\t" << endl;
cout << d << " 加 " << e << " 等于 " << f << setprecision(10) << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 2://减
cout << "--------------------减法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> a;
cout << "您输入的数字为:" << a << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> b;
cout << "您输入的数字为:" << b << endl;
c = a - b;//运算结果
cout << "--------------------------------------------\t" << endl;
cout << a << " 减 " << b << " 等于 " << c << setprecision(10) << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 4://乘法口诀表
cout << "-----------------乘法口诀表-----------------\t" << endl;
for (int n9 = 1; n9 <= 9; n9++)
{
for (int m9 = 1; m9 <= n9; m9++)
{
cout << m9 << "*" << n9 << "=" << m9 * n9 << "\t";
}
cout << endl;
}
cout << "--------------------------------------------\t" << endl;
break;
case 5://鸡兔同笼
cout << "-----------------鸡兔同笼题-----------------\t" << endl;
cout << "鸡和兔一共有多少只" << endl;
cin >> zhi;
cout << "鸡和兔一共有多少脚" << endl;
cin >> jiao;
tu = (jiao - (2 * zhi));
tu = tu / 2;
ji = zhi - tu;
cout << "鸡有:" << ji << "只\n" << "兔有:" << tu << "只" << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;
case 6:
cout << "-----------------圆面积计算-----------------\t" << endl;
cout << "请输入圆的半径:" << endl;
cin >> radius;
area = radius * radius * pi_;
cout << "圆的半径是:" << setprecision(15) << radius << "圆的面积是:" << area << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;
case 3://乘除选择
cout << "------------------乘除选择------------------\t" << endl;
cout << "乘法还是除法?" << endl;
cout << "1,乘法" << endl;
cout << "2,除法" << endl;
cout << "--------------------------------------------\t" << endl;
cin >> chengchu;
system("cls");//清空上面内容
switch (chengchu)
{
case 1://乘
cout << "------------------乘法----------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> g;
cout << "您输入的数字为:" << g << endl;
cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> h;
cout << "您输入的数字为:" << h << endl;
i = g * h;//运算结果
cout << "--------------------------------------------\t" << endl;
cout << g << " 乘 " << h << " 等于 " << i << setprecision(10) << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
case 2://除
cout << "--------------------除法--------------------\t" << endl;
cout << "请输入第一个数字:" << endl;
cin >> k;
cout << "您输入的数字为:" << k << endl;
L2:cout << "--------------------------------------------\t" << endl;
cout << "请输入第二个数字:" << endl;
cin >> n;
cout << "您输入的数字为:" << n << endl;
cout << "--------------------------------------------\t" << endl;
if (n)
{
l = k / n;//运算结果
cout << k << " 除 " << n << " 等于 " << setprecision(10) << l << endl;
cout << "-----------------运算完成-------------------\t" << endl;
break;//结束分支,不加否则继续执行
}
else
{
cout << "第二个数字不能小于等于0!" << endl;
goto L2;
}
break;
default:
break;
}
default:
break;
}
cout << "1,重新开始 2,退出程序" << endl;//选择继续运行还是退出
cin >> jieshu;
switch (jieshu)
{
case 1:
system("cls");//清空并重新运行l1内容
goto L1;
case 2:
cout << "-----------------回车退出-------------------\t" << endl;
end = clock();
ret = double(end - begin) / CLOCKS_PER_SEC;
cout << endl;
cout << "程序运行时间: " << setprecision(10) << ret << "秒" << endl;
system("pause");//退出程序
default:
break;
}
}
}