C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.一定要用友元哦,顺便带上main函数的类容

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 02:31:16
C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.一定要用友元哦,顺便带上main函数的类容

C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.一定要用友元哦,顺便带上main函数的类容
C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.
一定要用友元哦,顺便带上main函数的类容

C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.一定要用友元哦,顺便带上main函数的类容
#include <iostream>
using namespace std;

const double PI = 3.141592653;
class Point
{
public:
double X;
double Y;
public:
Point() : X(0), Y(0){};
Point(double x, double y) : X(x), Y(y){};
};

class Circle : public Point
{
double R;
friend double GetArea(Circle*);
public :
Circle() : R(0){};
Circle(double r) : R(r){};

inline double GetR() { return R; };
inline void SetR(double r) { R = r; };
};

class Cylinder : public Circle
{
double H;
friend double GetVolume(Cylinder*);
public:
Cylinder() : H(0) {};
Cylinder(double r, double h) : Circle(r), H(h){};
inline double GetH() { return H; };
inline void SetH(double r) { H = r; };
};

void main()
{
double r,h;
cout << "请输入圆半径:"<<endl;
cin >> r;
Circle c(r);
cout << "请输入圆柱底面半径和圆柱高:"<<endl;
cin >> r >> h;
Cylinder cy(r, h);
cout << "圆面积为:" << GetArea(&c) << endl;
cout << "圆柱底面积为:" << GetArea(&cy) << "圆柱体积为:" << GetVolume(&cy) << endl;
}

double GetArea(Circle* c)
{
return PI*c->R*c->R;
}

double GetVolume(Cylinder* c)
{
return GetArea(c)*c->H;
}

定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积. point类的设计 C++(1)定义Point类,能够设置、获取并打印出点的X、Y坐标,要求声明在Point.h中,实现在Point.cpp中.(2)定义Circle类,能够设置、获取并打印出圆心(X、Y坐标)和半径,并能够判断两 尤其是“另定义point类实现”和“类属性”定义几何图形圆的类Circle,包括圆心O(另定义point类实现)和半径R两个属性 定义一个Point类,派生出Rectangle类和Circle类,计算各 派生类对象的面积Area(). C++定义Point,Circle,Cylinder类.用友元求(friend)圆面积,圆柱体体积.一定要用友元哦,顺便带上main函数的类容 编写几何图形圆的类Circle,包括两个属性:圆心O(另定义Point(点)类实现)和半径R.看到c++头都大啦 .写一个C++程序,定义抽象基类Shape,由它派生出一个基类Point,再由Point派生出2个派生类:Circle(圆形) C++ 定义1个点类Point,一个圆类Circle,一个圆柱体类Cylinder,点类派生圆类,圆类派生圆定义1个点类Point,一个圆类Circle,一个圆柱体类Cylinder,点类派生圆类,圆类派生圆柱体类.点类中含有x、y坐标,构 急!C++问题,先定义“点”类Point,由“点”类派生出“圆”类Circle,再由“圆”类生成“圆柱体”类先定义“点”类Point,由“点”类派生出“圆”类Circle,再由“圆”类生成“圆柱体”类cylinder.圆 【程序设计】---------------------------------------------------------定义一个点类Point包括x坐标和y坐标(int).定义一个圆类Circle,有数据成员半径和表示圆心坐标的点类对象.圆类成员函数包括构 cy CY 定义一个类LOCATION,用数据成员x,y表示该类对象在二维坐标系的坐标位置用函数成员move移动对象坐标位置,然后以类LOCATION为基类派生出点类POINT再利用点类POINT派生出圆类CIRCLE.定义点类和圆类 java 如下写了Circle类 构造函数 在测试程序中 new一个circle在第9行 提示错误Circle类型不可用 怎样改?1 class Circle{2 Point o;3 double radius;4 Circle(Point p,double r){5 o = p;6 radius = r;7 }8 Point d1 = new Point(2.0,2. 英文名以C开头,首字母CY CY Opening PSS C/S ETD PRC 若x/a=y/b,则:(pa+cx)/(qa+cy)与(pb+cy)/(qb+cy)的关系是( )A 当p>q时,(pa+cx)/(qa+cy)>(pb+cy)/(qb+cy)B 当p(pb+cy)/(qb+cy)C (pa+cx)/(qa+cy)与(pb+cy)/(qb+cy)不相等D (pa+cx)/(qa+cy)与(pb+cy)/(qb+cy)相等E 以上结果都不正确D请 Quality Circle(质量圈)的中英文定义,