c++类的使用出了问题,在主函数中调用类中成员函数时编译报错

c++类的使用出了问题,在主函数中调用类中成员函数时编译报错

问题描述:

#include
using namespace std;
#define PI 3.141592657
class cylinder
{
public:
void Set(double x,double y);
double Volume();
void showVolume();
private:
double R,H,V;
};
void cylinder::Set(double x,double y)
{
R=x;
H=y;
}
double cylinder::Volume()
{
return (PI*R*R*H);
}
void cylinder::showVolume()
{
cout<<"体积为:"< }
int main()
{
double a,b;
cin>>a>>b;
cylinder.Volume(a,b);
return 0;
}

上述代码执行会一直提示cylinder.Volume(a,b)处有语法错误,找了很久找不到问题所在。

#include<iostream>
using namespace std;
#define PI 3.141592657
class cylinder
{
public:
    void Set(double x,double y);
    double Volume();
    void showVolume();
private:
    double R,H,V;
};
void cylinder::Set(double x,double y)
{
    R=x;
    H=y;
}
double cylinder::Volume()
{
    return (PI*R*R*H);
}
void cylinder::showVolume()
{
    cout<<"体积为:"<<Volume()<<endl;
}
int main()
{
    double a,b;
    cin>>a>>b;
    cylinder c;
    c.Set(a, b);
    double d = c.Volume();
    cout << d;
    return 0;
}

顺便说下,你这个圆周率是错的。
圆周率等于 3.14159265358979323846...
你弄个57算怎么回事。