习题3.22:
#include<iostream>
using namespace std;
const float p=3.14;
class Circle{
private:
float radius;
public:
Circle(float r)
{
radius=r;
}
float area()
{i
return p*radius*radius;
}
void showArea()
{
cout<<area()<<endl;
}
};
int main()
{
Circle cir1(1.00);
cout<<"该圆的面积为:";
cir1.showArea();
return 0;
}
习题3.23
<pre name="code" class="cpp">#include<iostream>
using namespace std;
class Cylinder
{
public:
Cylinder(double h,double r);
double getV();
void vol();
private:
double hight;
double radius;
};
Cylinder::Cylinder(double h,double r)
{
hight=h;
radius=r;
}
double Cylinder::getV()
{
return 3.14*radius*radius*hight;
}
void Cylinder::vol()
{
cout<<getV()<<endl;
}
int main()
{
Cylinder Clin1(