首页 > 其他分享 >以圆类Circle及立体图形类Solid为基础设计圆柱类Cylinder

以圆类Circle及立体图形类Solid为基础设计圆柱类Cylinder

时间:2023-05-23 12:34:46浏览次数:34  
标签:Cylinder 以圆类 const Point Solid double run Circle

以点类Point及平面图形类Plane为基类公有派生圆类Circle,再以圆类Circle及立体图形类Solid为基类公有派生圆柱类Cylinder,main(void)函数完成对圆柱类Cylinder的测试。

Point类结构说明:

 
Point类的数据成员包括:
①私有数据成员:X坐标x(double型),Y坐标y(double型)。
Point类成员函数包括:
①有参构造函数Point(double, double)和拷贝构造函数Point(const  Point  &),其中有参构造函数参数默认值为0,输出信息“Point Constructor run”,拷贝构造函数输出信息“Point CopyConstructor run”
②析构函数,析构函数输出信息“Point Destructor run”
③公有函数成员:void  setX(double)和double getX() const分别返回和设置X坐标
④公有函数成员:void  setY(double)和double getY() const分别返回和设置Y坐标
⑤公有成员函数void show() const用于显示点的坐标信息,显示格式为:Point(X=<X坐标>,Y=<Y坐标>)
 

Plane类结构说明:

 
Plane类的成员函数包括:
①纯虚函数virtual double length()const用于计算平面图形的周长
②纯虚函数virtual double area()const用于计算平面图形的面积
 

Solid类结构说明:

 
Solid类的成员函数包括:
①纯虚函数virtual double volume()const用于计算立体图形的体积
②纯虚函数virtual double s_Area()const用于计算立体图形的表面积
 

Circle类结构说明:

 
公有派生圆类Circle以点类Point、平面图形类Plane为基类,Circle类的结构说明如下:
Circle类的数据成员包括:
①圆心坐标继承自Point类
②保护静态数据常量PI(double型),其值为3.14159
③私有数据成员:半径radius(double型)。
Circle类成员函数包括:
①有参构造函数Circle(double, double, double)和拷贝构造函数Circle(const Circle &),其中有参构造函数参数包括圆心坐标和半径,圆心调用Point类构造函数进行构造,各参数默认值为0,输出信息“Circle Constructor run”,拷贝构造函数输出信息“Circle CopyConstructor run”
②析构函数,析构函数输出信息“Circle Destructor run”
③公有函数成员void setR(double)和double getR()const分别返回和设置radius
④重载void show()const用于显示圆的信息,显示格式为:
Circle(Point(<圆心X坐标>,<圆心Y坐标>),Radius=<半径>)
⑤重载double area()const用于计算圆的面积
⑥重载double length()const用于计算圆的周长
 

Cylinder类结构说明:

 
公有派生圆柱类Cylinder以圆类Circle、立体图形类Solid为基类,Cylinder类的结构说明如下:
Cylinder类的数据成员包括:
①基圆继承自Circle类
②私有数据成员:高度 height(double型)
Cylinder类成员函数包括:
①有参构造函数Cylinder(double, double, double, double)和拷贝构造函数Cylinder(const Cylinder &),其中有参构造函数参数包括基圆圆心坐标、半径和高度,基圆调用Circle类构造函数进行构造,各参数默认值为0,输出信息“Cylinder Constructor run”,拷贝构造函数输出信息“Cylinder CopyConstructor run”
②析构函数,析构函数输出信息“Cylinder Destructor run”
③重载void show()const用于显示圆柱的信息,显示格式为:
Cylinder(Circle(Point(<球心X坐标>,<球心Y坐标>),Radius=<半径>),Height=<高度>)
④重载double s_Area()const用于计算圆柱的面积
⑤重载double volume()const用于计算圆柱的体积
 

裁判测试程序样例:

 
#include <iostream>
using namespace std;
//点类Point
class Point{
private:
    double x;
    double y;
public:
    Point(double xv=0,double yv=0);/*构造函数*/
    Point(const Point &p);         /*拷贝构造*/
    ~Point();                      /*析构函数*/
    void setX(double xv);          /*设置X坐标*/
    void setY(double yv);          /*设置Y坐标*/
    double getX()const;            /*获取X坐标*/
    double getY()const;            /*获取Y坐标*/
    virtual void show()const;      /*显示*/
};
Point::Point(const double xv,const double yv){/*构造函数*/
    x=xv;
    y=yv;
    cout<<"Point Constructor run"<<endl;
}
Point::Point(const Point &p){/*拷贝构造*/
    x=p.x;
    y=p.y;
    cout<<"Point CopyConstructor run"<<endl;
}
Point::~Point(){/*析构函数*/
    cout<<"Point Destructor run"<<endl;
}
void Point::setX(double xv){/*设置X坐标*/
    x=xv;
}
void Point::setY(double yv){/*设置Y坐标*/
    y=yv;
}
double Point::getX()const{/*获取X坐标*/
    return x;
}
double Point::getY()const{/*获取Y坐标*/
    return y;
}
void Point::show()const{/*显示*/
    cout<<"Point(X="<<x<<",Y="<<y<<")";
}
//平面图形类Plane
class Plane{
public:
    virtual double length()const=0;/*周长*/
    virtual double area()const=0;  /*面积*/
};
//立体图形类Solid
class Solid{
public:
    virtual double volume()const=0;/*体积*/
    virtual double s_Area()const=0;/*表面积*/
};

/*请在这里填写答案*/

void show(Point *p){/*点基类的显示函数*/
    p->show();
}
void length(Plane *p){/*平面图形的周长函数*/
    cout<<"Length="<<p->length()<<endl;
}
void area(Plane &p){/*平面图形的面积函数*/
    cout<<"Area="<<p.area()<<endl;
}

void volumn(Solid *s){/*立体图形的体积函数*/
    cout<<"Volumn="<<s->volume()<<endl;
}
void s_Area(Solid &s){/*立体图形的表面积函数*/
    cout<<"S_Area="<<s.s_Area()<<endl;
}
//主函数
int main(void){
    double  h;
    cin>>h;
    Cylinder cy1(1,2,3,4),cy2(cy1);
    show(&cy1);
    cout<<endl;
    area(cy1);
    length(&cy1);
    s_Area(cy1);
    volumn(&cy1);
    cy2.setH(h);
    show(&cy2);
    cout<<endl;
    area(cy2);
    length(&cy2);
    s_Area(cy2);
    volumn(&cy2);
    return 0;
}
 

输入样例:

1.0
 

输出样例:

Point Constructor run
Circle Constructor run
Cylinder Constructor run
Point CopyConstructor run
Circle CopyConstructor run
Cylinder CopyConstructor run
Cylinder(Circle(Point(X=1,Y=2),Radius=3),Height=4)
Area=28.2743
Length=18.8495
S_Area=131.947
Volumn=113.097
Cylinder(Circle(Point(X=1,Y=2),Radius=3),Height=1)
Area=28.2743
Length=18.8495
S_Area=75.3982
Volumn=28.2743
Cylinder Destructor run
Circle Destructor run
Point Destructor run
Cylinder Destructor run
Circle Destructor run
Point Destructor run






class Circle:public Point,public Plane
{
private:
double radius;
public:
static double PI;
Circle(double x1=0,double x2=0,double r1=0);
Circle(const Circle &P);
~Circle();
void setR(double r2);
double getR() const;
void show() const;
double area() const;
double length() const;
};
double Circle::PI=3.14159;
Circle::Circle(double x1,double x2,double r1):Point(x1,x2)
{
radius=r1;
cout<<"Circle Constructor run"<<endl;
}
Circle::Circle(const Circle &p):Point(p)
{
radius=p.radius;
cout<<"Circle CopyConstructor run"<<endl;
}
Circle::~Circle()
{
cout<<"Circle Destructor run"<<endl;
}
void Circle::setR(double r2)
{
radius=r2;
}
double Circle::getR() const
{
return radius;
}
void Circle::show() const
{
cout<<"Circle(Point(X="<<getX()<<",Y="<<getY()<<"),Radius="<<radius<<")";
}
double Circle::area() const
{
return PI*radius*radius;
}
double Circle::length() const
{
return 2*PI*radius;
}
class Cylinder:public Circle,public Solid
{
private:
double height;
public:
Cylinder(double x=0,double y=0,double r=0,double h=0);
Cylinder(const Cylinder &p);
~Cylinder();
void setH(double h);
void show() const;
double s_Area()const;
double volume()const;
};
Cylinder::Cylinder(double x,double y,double r,double h):Circle(x,y,r)
{
height=h;
cout<<"Cylinder Constructor run"<<endl;
}
Cylinder::Cylinder(const Cylinder &p):Circle(p)
{
height=p.height;
cout<<"Cylinder CopyConstructor run"<<endl;
}
Cylinder::~Cylinder()
{
cout<<"Cylinder Destructor run"<<endl;
}
void Cylinder::setH(double h)
{
height=h;
}
void Cylinder::show() const
{
cout<<"Cylinder(Circle(Point(X="<<getX()<<",Y="<<getY()<<"),Radius="<<getR()<<"),Height="<<height<<")";
}
double Cylinder::s_Area() const
{
return 2*PI*getR()*getR()+2*PI*getR()*height;
}
double Cylinder::volume() const
{
return PI*getR()*getR()*height;
}

标签:Cylinder,以圆类,const,Point,Solid,double,run,Circle
From: https://www.cnblogs.com/zljzy/p/17421594.html

相关文章

  • 模拟运行600万年 数据0损坏!Solidigm把QLC闪存玩到了极致
    不可否认的是,SLC、MLC、TLC、QLC、PLC、HLC……闪存技术一路走下来,整体的可靠性、寿命指标是逐步走低的,这也是NAND闪存架构天然属性所决定的。当然,这不代表QLC、PLC闪存的就难堪大用,关键是看如何设计与优化,从闪存、硬盘的硬件优化,再到主控、算法、负载的软件优化,都至关重要,也直接......
  • 以圆类Circle为基础设计球类Sphere
    以点类Point为基类公有派生圆类Circle,并以圆类Circle为基类公有派生球类Sphere,main(void)函数完成对其的测试。Point类结构说明:Point类的数据成员包括:①私有数据成员:X坐标x(double型),Y坐标y(double型)。Point类成员函数包括:①有参构造函数Point(double,double)和拷贝构造函......
  • SolidCAM_2022_SP2 Mult for SolidWorks完整CAD/CAM解决方案
    SolidCAM_2022_SP2MultforSolidWorks:完整CAD/CAM解决方案SolidCAM_2022_SP2MultforSolidWorks是一款完整的CAD/CAM解决方案,它为SolidWorks用户提供了一种高效、准确和可靠的加工解决方案。SolidCAM_2022_SP2MultforSolidWorks具有强大的功能和易于使用的界面,可以帮助用户......
  • 15.solidworks零件 另存为、另存为副本并继续、另存为副本并打开
    1.另存为A零件被另存为B后,装配体上的零件为B 2.另存为副本并继续A零件被另存为副本B并继续,界面显示的仍然为A,装配体上的零件为A,生成新的副本B并未打开 3.另存为副本并打开A零件被另存为副本B并打开,界面显示为B,装配体上的零件为A,生成新的副本B并打开......
  • Solidity-变量和数据类型[基本类型]
    在solidity语言中,变量和数据类型分为三类:基本类型(bool、int、address等),复合类型(array、struct、mapping等)和特殊类型(enum、function、modifier等)。下面我们来对”基本类型“部分进行详细学习。基本类型布尔类型(bool)布尔类型(bool)占用1个字节的存储空间,即8个比特位,该类型只能取......
  • 13.solidworks简单渲染教程
    1、打开solidworks,点击菜单栏的工具,然后选择插件,勾选PhotoView360两边的框2、右键特征工具栏,把渲染工具勾选3点击渲染工具,然后对想要更改的零件或者部位使用编辑外观和编辑布景更改外观颜色、材质、贴图以及背景4、在绘图区域先摆好一个适合的角度,然后再添加相机5、在右侧进行......
  • SolidWorks软件2023中文版下载安装,SolidWorks特色功能使用介绍
    SolidWorks是一款功能强大的3DCAD软件,广泛用于机械设计、生产制造、建筑设计等领域。在这些领域,SolidWorks软件的独特功能,如先进的拓扑优化、高级可视化和实时模拟等,为用户提供了方便快捷、智能高效的设计体验。一、先进的拓扑优化SolidWorks软件提取:soruan.top/TPqqfb.SolidWorks......
  • 以圆类Circle及立体图形类Solid为基础设计圆锥类Cone
    以点类Point及平面图形类Plane为基类公有派生圆类Circle,再以圆类Circle及立体图形类Solid为基类公有派生圆锥类Cone,main(void)函数完成对圆锥类Cone的测试。Point类结构说明: Point类的数据成员包括:①私有数据成员:X坐标x(double型),Y坐标y(double型)。Point类成员函数包括:①......
  • pta_【CPP0029】以圆类Circle及立体图形类Solid为基础设计圆锥类Cone
    #include<iostream>#include<cmath>usingnamespacestd;//点类PointclassPoint{private:doublex;doubley;public:Point(doublexv=0,doubleyv=0);/*构造函数*/Point(constPoint&p);/*拷贝构造*/~Point();/*......
  • Hardhat 开发框架 - Solidity开发教程连载
    Decert.me要连载教程了,《Solidity开发教程》力求系统、深入的介绍Solidity开发,同时这是一套交互式教程,你可以实时的修改教程里的合约代码并运行。本教程来自贡献者@Tiny熊,让我们正式开始学习吧。如果你已经是Hardhat的使用者,可以直接跳到文末,参与挑战领取技能认证NF......