我只能得到它。这有什么问题?
请查看错误并帮助我。它显示错误。我就是不明白问题出在哪里??我已经解决了所有可以解决的错误,但我仍然陷入困境。我知道这是一个非常简单的问题,而且非常令人沮丧。
问题是: 创建一个使用两个单独函数的计算类:一个函数用于将两个浮点数相乘,另一个函数使用内联函数的概念来除两个浮点数。另外,创建一个在屏幕上打印结果的方法。
#include <iostream>
using namespace std;
class calculate
{
float a,b;
public:
float multiply(float a, float b);
float divide(float a, float b);
};
inline float calculate :: multiply(float a, float b)
{
return a*b;
}
inline float calculate :: divide(float a, float b)
{
return a/b;
}
int main()
{
float a,b;
cout<<"Enter two float numbers: ";
cin>>a>>b;
calculate obj (a,b);
cout<<"Multiplication: "<<obj.multiply(a,b)<<endl;
cout<<"Division: "<<obj.divide(a,b)<<endl;
return 0;
}
Please see the error and help me. Its showing error. I just can't understand where is the problem?? I have resolved all the errors that could be solved but still I am stuck. I know this is a vey simple question and its very frustrating.
The question is:
Create a class calculate that uses two separate functions:-a function to multiply two float numbers and another to divide two float numbers using the concept of inline function. Also, create a method to print the result on the screen.
#include <iostream>
using namespace std;
class calculate
{
float a,b;
public:
float multiply(float a, float b);
float divide(float a, float b);
};
inline float calculate :: multiply(float a, float b)
{
return a*b;
}
inline float calculate :: divide(float a, float b)
{
return a/b;
}
int main()
{
float a,b;
cout<<"Enter two float numbers: ";
cin>>a>>b;
calculate obj (a,b);
cout<<"Multiplication: "<<obj.multiply(a,b)<<endl;
cout<<"Division: "<<obj.divide(a,b)<<endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译程序会产生编译器错误:
这告诉您,在构造
计算
对象的线路上,通过调用一个构造函数,该构造函数获取两个float参数,没有这样类中的构造函数计算
存在。看课,您没有定义任何此类构造函数。这很容易解决:
现在您的班级可以按照您的意愿构建:
Compiling your program yields the compiler error:
This is telling you that on the line where you construct a
calculate
object namedobj
by invoking a constructor that takes two float arguments, no such constructor in the classcalculate
exists.Looking at the class, you did not define any such constructor. This is easily fixed:
Now your class can be constructed as you wanted: