#include<iostream>
using namespace std;
class cylinder{
public:
cylinder(double a,double b);
void vol();
private:
double r;
double h;
double volume;
};
cylinder::cylinder(double a,double b)
{
r=a;
h=b;
volume=3.1415*r*r*h;
}
void cylinder::vol()
{
cout<<"The volume is :"<<volume<<endl;
}
int main()
{
cylinder x(1.0,1.0);
x.vol();
system("pause");
return 0;
} 3.23
最新推荐文章于 2025-07-28 16:42:22 发布
This blog demonstrates how to calculate the volume of a cylinder using C++ programming language, including class definition, constructor usage, and method implementation.
1414





