请帮忙看看这个C++程序那里错了
程序代码如下,我想用C++的类实现一个简单计算器的功能,但是编译时总是出错。请帮忙看看那里错了!谢谢#include"iostream.h"classcal;intmai...
程序代码如下,我想用C++的类实现一个简单计算器的功能,但是编译时总是出错。请帮忙看看那里错了!谢谢
#include "iostream.h"
class cal;
int main()
{
float a,b,c;
char m;
cal jisuanqi;
cout<<"输入两个数a,b:"<<endl;
cin>>a>>b;
cout<<"输入运算符号(+、-、*、/):"<<endl;
cin>>m;
switch (m)
{
case '+':
cout<<jisuanqi.jia(a,b)<<endl;
break;
case '-':
cout<<jisuanqi.jian(a,b)<<endl;
break;
case '*':
cout<<jisuanqi.cheng(a,b)<<endl;
break;
case '/':
cout<<jisuanqi.chu(a,b)<<endl;
break;
default:
cout<<"程序有错误!!"<<endl;
}
return 0;
}
class cal
{
public:
float jia(float a,float b)
{
return a+b;
}
float jian(float a,float b)
{
return a-b;
}
float cheng(float a,float b)
{
return a*b;
}
float chu(float a,float b)
{
if(b==0)
{
cout<<"错误!除数不能为零!!"<<endl;
}
else
{
return a/b;
}
}
}; 展开
#include "iostream.h"
class cal;
int main()
{
float a,b,c;
char m;
cal jisuanqi;
cout<<"输入两个数a,b:"<<endl;
cin>>a>>b;
cout<<"输入运算符号(+、-、*、/):"<<endl;
cin>>m;
switch (m)
{
case '+':
cout<<jisuanqi.jia(a,b)<<endl;
break;
case '-':
cout<<jisuanqi.jian(a,b)<<endl;
break;
case '*':
cout<<jisuanqi.cheng(a,b)<<endl;
break;
case '/':
cout<<jisuanqi.chu(a,b)<<endl;
break;
default:
cout<<"程序有错误!!"<<endl;
}
return 0;
}
class cal
{
public:
float jia(float a,float b)
{
return a+b;
}
float jian(float a,float b)
{
return a-b;
}
float cheng(float a,float b)
{
return a*b;
}
float chu(float a,float b)
{
if(b==0)
{
cout<<"错误!除数不能为零!!"<<endl;
}
else
{
return a/b;
}
}
}; 展开
2个回答
展开全部
你用下面这个
#include "iostream.h"
class cal
{
public:
float jia(float a,float b)
{
return a+b;
}
float jian(float a,float b)
{
return a-b;
}
float cheng(float a,float b)
{
return a*b;
}
float chu(float a,float b)
{
if(b==0)
{
cout<<"错误!除数不能为零!!"<<endl;
}
else
{
return a/b;
}
}
};
int main()
{
float a,b,c;
char m;
cal jisuanqi;
cout<<"输入两个数a,b:"<<endl;
cin>>a>>b;
cout<<"输入运算符号(+、-、*、/):"<<endl;
cin>>m;
switch (m)
{
case '+':
cout<<jisuanqi.jia(a,b)<<endl;
break;
case '-':
cout<<jisuanqi.jian(a,b)<<endl;
break;
case '*':
cout<<jisuanqi.cheng(a,b)<<endl;
break;
case '/':
cout<<jisuanqi.chu(a,b)<<endl;
break;
default:
cout<<"程序有错误!!"<<endl;
}
return 0;
}
还有引用标准库最好用#include <iostream.h>
#include "iostream.h"
class cal
{
public:
float jia(float a,float b)
{
return a+b;
}
float jian(float a,float b)
{
return a-b;
}
float cheng(float a,float b)
{
return a*b;
}
float chu(float a,float b)
{
if(b==0)
{
cout<<"错误!除数不能为零!!"<<endl;
}
else
{
return a/b;
}
}
};
int main()
{
float a,b,c;
char m;
cal jisuanqi;
cout<<"输入两个数a,b:"<<endl;
cin>>a>>b;
cout<<"输入运算符号(+、-、*、/):"<<endl;
cin>>m;
switch (m)
{
case '+':
cout<<jisuanqi.jia(a,b)<<endl;
break;
case '-':
cout<<jisuanqi.jian(a,b)<<endl;
break;
case '*':
cout<<jisuanqi.cheng(a,b)<<endl;
break;
case '/':
cout<<jisuanqi.chu(a,b)<<endl;
break;
default:
cout<<"程序有错误!!"<<endl;
}
return 0;
}
还有引用标准库最好用#include <iostream.h>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询