C++编程:定义一个基类Cylinder,数据成员包括有半径(radius),高度(high);

2025-04-07 00:45:17
推荐回答(1个)
回答1:

#include 
using namespace std;
#define PI 3.1415926
class Cylinder{
private:
float radius,high;
public:
Cylinder(float r,float h):radius(r),high(h){};
float GetAtee();
float GetVolume();
};
float Cylinder::GetAtee(){return PI*radius*2*high + PI*radius*radius*2;}
float Cylinder::GetVolume(){return PI*radius*radius*high;}
void main(){
Cylinder cy(1,1);
cout<cout<}