#include<iostream>
#include<cmath>
using namespace std;
void Addition(double a,double b)
{
cout<<a+b<<endl;
}
void Subtraction(double a,double b)
{
if(a>b)
cout<<a-b<<endl;
else
cout<<"-"<<b-a<<endl;
}
void Multiplication(double a,double b)
{
cout<<a*b<<endl;
}
void Division(double a,double b)
{
cout<<a/b<<endl;
}
void Root(double a)
{
cout<<sqrt(a)<<endl;
}
void Involution(double a,double b)
{
cout<< pow(a,b)<<endl;
}
int main()
{
int x;
double a = 0.0,b = 0.0;
cout<<"0代表加法\n"<<"1代表减法\n"<<"2代表乘法\n"<<"3代表除法\n"<<"4代表根号\n"<<"5代表平方\n"<<"6代表退出计算\n"<<endl;
cout<<"请输入计算方式的代号:\t";
cin>>x;
cout<<"已为您转入计算空间"<<x<<"."<<endl;
do
{
switch(x)
{
case 0:
{
cout<<"请输入:\t";
cin>>a>>b;
Addition(a,b);
break;
}
case 1:
{
cout<<"请输入:\t";
cin>>a>>b;
Subtraction(a,b);
break;
}
case 2:
{
cout<<"请输入:\t";
cin>>a>>b;
Multiplication(a,b);
break;
}
case 3:
{
cout<<"请输入:\t";
cin>>a>>b;
Division(a,b);
break;
}
case 4:
{
cout<<"请输入:\t";
cin>>a;
Root(a);
break;
}
case 5:
{
cout<<"请输入:\t";
cin>>a>>b;
Involution(a,b);
break;
}
case 6:
break;
}
}
while(x);
}
上面这幅图展示的是乘方运行结果。