用c++编写计算器程序
看到你曾经帮别人回答过编写计算器的问题,能不能把代码也借我用一下啊,我们最近也为这代码发愁呢,谢谢了!!...
看到你曾经帮别人回答过编写计算器的问题,能不能把代码也借我用一下啊,我们最近也为这代码发愁呢,谢谢了!!
展开
2个回答
2013-12-31
展开全部
#include <iostream>using namespace std;int main(){double x,y;char z;cout<<"请输入第一个数字:"<<endl;cin>>x;cout<<"请输入第二个数字:"<<endl;cin>>y;cout<<"请输入输入运算符号(+、-、*、/):"<<endl;cin>>z;cout.precision(7);switch(z){case '+':cout<<"结果:"<< x+y<<endl;break;case '-':cout<<"结果:"<< x-y<<endl;break;case '*':cout<<"结果:"<< x*y<<endl;break;case '/':cout<<"结果:"<< x/y<<endl;break;default:cout<<"请输入正确的运算符号。"<<endl;}system("pause");return 0;}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-31
展开全部
Calculate.h
#include <iostream>
#include <math.h>
#define PI 3.1415926
using namespace std;
class Calculate{
private:
float xx,yy,zz;
public:
Calculate(){}
Calculate(float x,float y,float z){
this->xx=x;
this->yy=y;
this->zz=z;
}
float setxx(float a){
this->xx=a;
return 0;
}
float setyy(float b){
this->yy=b;
return 0;
}
float setzz(float c){
this->zz=c;
return 0;
}
float getxx(float a){
return a;
}
float getyy(float b){
return b;
}
float getzz(float c){
return c;
}
void Add(){
float a,b,c;
cout << "请输入要相加的两个数:"<<endl;
cin>>a>>b;
c=a+b;
cout << "c="<<c<<endl;
}
void Minus(){
float a,b,c;
cout << "请输入要相减的两个数:"<<endl;
cin>>a>>b;
c=a-b;
cout << "c="<<c<<endl;
}
void Multip(){
float a,b,c;
cout<<"请输入要相乘的两个数:"<<endl;
cin>>a>>b;
c=a*b;
cout << "结果为:"<<c<<endl;
}
void Divid(){
float a,b,c;
cout<<"请输入被除数和除数:"<<endl;
cin>>a>>b;
if(b==0) {
cout<<"除数不能为0,请重新输入除数"<<endl;
cin>>b;}
c=a/b;
cout << "结果为:"<<c<<endl;
}
void Sin(){
float x,i;
const double HD=PI/180;
cout<<"请输入您要计算的角度:"<<endl;
cin>>i;
cout<<"x\tsin(x)"<<endl;
cout<<i<<"\t"<<sin(i*HD)<<endl;
}
void Cos(){
float x,i;
const double HD=PI/180;
cout<<"请输入您要计算的角度:"<<endl;
cin>>i;
cout<<"x\tcos(x)"<<endl;
cout<<i<<"\t"<<cos(i*HD)<<endl;
}
void Asin(){
float x,i;
const double D=180/PI;
cout<<"请输入要计算的反正弦的值:"<<endl;
cin>>i;
cout<<"x\tasin(x)"<<endl;
cout<<i<<"\t"<<asin(i)*D<<endl;
}
void Acos(){
float x,i;
const double D=180/PI;
cout<<"请输入要计算的反余弦的值:"<<endl;
cin>>i;
cout<<"x\tacos(x)"<<endl;
cout<<i<<"\t"<<acos(i)*D<<endl;
}
};
主函数在下边,都放在这放不了。o(∩_∩)o...
#include <iostream>
#include <math.h>
#define PI 3.1415926
using namespace std;
class Calculate{
private:
float xx,yy,zz;
public:
Calculate(){}
Calculate(float x,float y,float z){
this->xx=x;
this->yy=y;
this->zz=z;
}
float setxx(float a){
this->xx=a;
return 0;
}
float setyy(float b){
this->yy=b;
return 0;
}
float setzz(float c){
this->zz=c;
return 0;
}
float getxx(float a){
return a;
}
float getyy(float b){
return b;
}
float getzz(float c){
return c;
}
void Add(){
float a,b,c;
cout << "请输入要相加的两个数:"<<endl;
cin>>a>>b;
c=a+b;
cout << "c="<<c<<endl;
}
void Minus(){
float a,b,c;
cout << "请输入要相减的两个数:"<<endl;
cin>>a>>b;
c=a-b;
cout << "c="<<c<<endl;
}
void Multip(){
float a,b,c;
cout<<"请输入要相乘的两个数:"<<endl;
cin>>a>>b;
c=a*b;
cout << "结果为:"<<c<<endl;
}
void Divid(){
float a,b,c;
cout<<"请输入被除数和除数:"<<endl;
cin>>a>>b;
if(b==0) {
cout<<"除数不能为0,请重新输入除数"<<endl;
cin>>b;}
c=a/b;
cout << "结果为:"<<c<<endl;
}
void Sin(){
float x,i;
const double HD=PI/180;
cout<<"请输入您要计算的角度:"<<endl;
cin>>i;
cout<<"x\tsin(x)"<<endl;
cout<<i<<"\t"<<sin(i*HD)<<endl;
}
void Cos(){
float x,i;
const double HD=PI/180;
cout<<"请输入您要计算的角度:"<<endl;
cin>>i;
cout<<"x\tcos(x)"<<endl;
cout<<i<<"\t"<<cos(i*HD)<<endl;
}
void Asin(){
float x,i;
const double D=180/PI;
cout<<"请输入要计算的反正弦的值:"<<endl;
cin>>i;
cout<<"x\tasin(x)"<<endl;
cout<<i<<"\t"<<asin(i)*D<<endl;
}
void Acos(){
float x,i;
const double D=180/PI;
cout<<"请输入要计算的反余弦的值:"<<endl;
cin>>i;
cout<<"x\tacos(x)"<<endl;
cout<<i<<"\t"<<acos(i)*D<<endl;
}
};
主函数在下边,都放在这放不了。o(∩_∩)o...
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询