定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 14:13:26
定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.
定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.
定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.
#include using namespace std;const double PI = 3.141592653;class Point{public:\x05double X;\x05double Y;public:\x05Point() :X(0),Y(0){};\x05Point(double x,double y) :X(x),Y(y){};};class Circle :public Point{\x05double R;\x05friend double GetArea(Circle*);public :\x05Circle() :R(0){};\x05Circle(double r) :R(r){};\x05inline double GetR() { return R; };\x05inline void SetR(double r) { R = r; };};class Cylinder :public Circle{\x05double H;\x05friend double GetVolume(Cylinder*);public:\x05Cylinder() :H(0) {};\x05Cylinder(double r,double h) :Circle(r),H(h){};\x05inline double GetH() { return H; };\x05inline void SetH(double r) { H = r; };};void main(){\x05double r,h;\x05cout h;\x05Cylinder cy(r,h);\x05cout