每日打卡一小时(第二十二天)

发布时间 2023-05-08 19:48:59作者: 伐木工熊大

一.问题描述

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

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用于计算圆的周长
Sphere类结构说明:
公有派生球类Sphere以圆类Circle、立体图形类Solid为基类,Sphere类的结构说明如下:
Sphere类的数据成员包括:
①基圆继承自Circle类
Sphere类成员函数包括:
①有参构造函数Sphere(double, double, double)和拷贝构造函数Sphere(const Sphere &),其中有参构造函数参数包括基圆圆心坐标和半径,基圆调用Circle类构造函数进行构造,各参数默认值为0,输出信息“Sphere Constructor run”,拷贝构造函数输出信息“Sphere CopyConstructor run”
②析构函数,析构函数输出信息“Sphere Destructor run”
③重载void show()const用于显示球的信息,显示格式为:
Sphere(Circle(Point(<球心X坐标>,<球心Y坐标>),Radius=<半径>))
④重载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  r;
    cin>>r;
    Sphere s1(1,2,3),s2(s1);
    show(&s1);
    cout<<endl;
    area(s1);
    length(&s1);
    s_Area(s1);
    volumn(&s1);
    s2.setR(r);
    show(&s2);
    cout<<endl;
    area(s2);
    length(&s2);
    s_Area(s2);
    volumn(&s2);
    return 0;
}
输入样例:
4.0

 

二.设计思路

  按照题目要求创建类,注意类中构造函数和复制构造函数的格式

三.代码实现

#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;/*表面积*/
};
class Circle :public Point, public Plane
{
protected:
    static double PI;
private:
    double radius;
public:
    Circle(double x1 = 0, double y1 = 0, double r1 = 0);
    Circle(const Circle& p);
    ~Circle();
    void setR(double r1);
    double getR()const;
    void show()const;
    double area()const;
    double length()const;
};
double Circle::PI = 3.14159;
Circle::Circle(double x1, double y1, double r1) :radius(r1), Point(x1, y1)
{
    cout << "Circle Constructor run" << endl;
}
Circle::Circle(const Circle& p) :Point(p)
{
    radius = p.getR();
    cout << "Circle CopyConstructor run" << endl;
}
Circle::~Circle()
{
    cout << "Circle Destructor run" << endl;
}
void Circle::setR(double r1)
{
    radius = r1;
}
double Circle::getR()const
{
    return radius;
}
void Circle::show()const
{
    cout << "Circle(Point(X=" << getX() << ",Y=" << getY() << "),Radius=" << getR() << ")";
}
double Circle::area()const
{
    return PI * radius * radius;
}
double Circle::length()const
{
    return PI * 2 * radius;
}
class Sphere :public Circle, public Solid
{
public:
    Sphere(double x1 = 0, double y1 = 0, double r = 0);
    Sphere(const Sphere& p);
    ~Sphere()
    {
        cout << "Sphere Destructor run" << endl;
    }
    void show()const;
    double s_Area()const;
    double volume()const;
};
Sphere::Sphere(double x1, double y1, double r) :Circle(x1, y1, r)
{
    cout << "Sphere Constructor run" << endl;
}
Sphere::Sphere(const Sphere& p) :Circle(p)
{
    cout << "Sphere CopyConstructor run" << endl;
}
void Sphere::show()const
{
    cout << "Sphere(Circle(Point(X=" << getX() << ",Y=" << getY() << "),Radius=" << getR() << "))";
}
double Sphere::s_Area()const
{
    return 4 * PI * getR() * getR();
}
double Sphere::volume()const
{
    return 4.0 / 3.0 * PI * getR() * getR() * getR();
}
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  r;
    cin >> r;
    Sphere s1(1, 2, 3), s2(s1);
    show(&s1);
    cout << endl;
    area(s1);
    length(&s1);
    s_Area(s1);
    volumn(&s1);
    s2.setR(r);
    show(&s2);
    cout << endl;
    area(s2);
    length(&s2);
    s_Area(s2);
    volumn(&s2);
    return 0;
}

一.问题描述

以点类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

二.代码实现

#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;/*表面积*/
};

class Circle :public Point, public Plane
{
protected:
    static double PI;
private:
    double radius;
public:
    Circle(double x1 = 0, double y1 = 0, double r1 = 0);
    Circle(const Circle& p);
    ~Circle();
    void setR(double r1);
    double getR()const;
    void show()const;
    double area()const;
    double length()const;
};
double Circle::PI = 3.14159;
Circle::Circle(double x1, double y1, double r1) :radius(r1), Point(x1, y1)
{
    cout << "Circle Constructor run" << endl;
}
Circle::Circle(const Circle& p) :Point(p)
{
    radius = p.getR();
    cout << "Circle CopyConstructor run" << endl;
}
Circle::~Circle()
{
    cout << "Circle Destructor run" << endl;
}
void Circle::setR(double r1)
{
    radius = r1;
}
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 PI * 2 * radius;
}
class Cylinder :public Circle, public Solid
{
    double height;
public:
    Cylinder(double x1 = 0, double y1 = 0, double r = 0, double h = 0);
    Cylinder(const Cylinder&);
    ~Cylinder()
    {
        cout << "Cylinder Destructor run" << endl;
    }
    void setH(double);
    double getH()const;
    void show()const;
    double s_Area()const;
    double volume()const;
};
Cylinder::Cylinder(double x1, double y1, double r, double h) :height(h), Circle(x1, y1, r)
{
    cout << "Cylinder Constructor run" << endl;
}
Cylinder::Cylinder(const Cylinder& p) :height(p.height), Circle(p)
{
    cout << "Cylinder CopyConstructor run" << endl;
}
void Cylinder::setH(double h)
{
    height = h;
}
double Cylinder::getH()const
{
    return height;
}
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;
}

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;
}

一.问题描述

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

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用于计算圆的周长
Cone类结构说明:
公有派生圆锥类Cone以圆类Circle、立体图形类Solid为基类,Cone类的结构说明如下:
Cone类的数据成员包括:
①基圆继承自Circle类
②私有数据成员:高度 height(double型)
Cone类成员函数包括:
①有参构造函数Cone(double, double, double,double)和拷贝构造函数Cone(const Cone &),其中有参构造函数参数包括基圆圆心坐标、半径和高度,基圆调用Circle类构造函数进行构造,各参数默认值为0,输出信息“Cone Constructor run”,拷贝构造函数输出信息“Cone CopyConstructor run”
②析构函数,析构函数输出信息“Cone Destructor run”
③重载void show()const用于显示圆锥的信息,显示格式为:
Cone(Circle(Point(<球心X坐标>,<球心Y坐标>),Radius=<半径>),Height=<高度>)
④重载double s_Area()const用于计算圆锥的面积
⑤重载double volume()const用于计算圆锥的体积
裁判测试程序样例:
#include <iostream>
#include<cmath>
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;
    Cone co1(1,2,3,4),co2(co1);
    show(&co1);
    cout<<endl;
    area(co1);
    length(&co1);
    s_Area(co1);
    volumn(&co1);
    co2.setH(h);
    show(&co2);
    cout<<endl;
    area(co2);
    length(&co2);
    s_Area(co2);
    volumn(&co2);
    return 0;
}
输入样例:
1.0

 

二.代码实现

#include <iostream>
#include<cmath>
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;/*表面积*/
};
#include<cmath>
class Circle :public Point, public Plane
{
protected:
    static double PI;
private:
    double radius;
public:
    Circle(double x1 = 0, double y1 = 0, double r1 = 0);
    Circle(const Circle& p);
    ~Circle();
    void setR(double r1);
    double getR()const;
    void show()const;
    double area()const;
    double length()const;
};
double Circle::PI = 3.14159;
Circle::Circle(double x1, double y1, double r1) :radius(r1), Point(x1, y1)
{
    cout << "Circle Constructor run" << endl;
}
Circle::Circle(const Circle& p) :Point(p)
{
    radius = p.getR();
    cout << "Circle CopyConstructor run" << endl;
}
Circle::~Circle()
{
    cout << "Circle Destructor run" << endl;
}
void Circle::setR(double r1)
{
    radius = r1;
}
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 PI * 2 * radius;
}
class Cone :public Circle, public Solid
{
    double height;
public:
    Cone(double x1 = 0, double y1 = 0, double r = 0, double h = 0);
    Cone(const Cone&);
    ~Cone()
    {
        cout << "Cone Destructor run" << endl;
    }
    void setH(double);
    double getH()const;
    void show()const;
    double s_Area()const;
    double volume()const;
};
Cone::Cone(double x1, double y1, double r, double h) :height(h), Circle(x1, y1, r)
{
    cout << "Cone Constructor run" << endl;
}
Cone::Cone(const Cone& p) :height(p.height), Circle(p)
{
    cout << "Cone CopyConstructor run" << endl;
}
void Cone::setH(double h)
{
    height = h;
}
double Cone::getH()const
{
    return height;
}
void Cone::show()const
{
    cout << "Cone(Circle(Point(X=" << getX() << ",Y=" << getY() << "),Radius=" << getR() << "),Height=" << height << ")";
}
double Cone::s_Area()const
{
    return PI * getR() * getR() + PI * getR() * sqrt(getR() * getR() + height * height);
}
double Cone::volume()const
{
    return PI * getR() * getR() * height / 3.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;
    Cone co1(1, 2, 3, 4), co2(co1);
    show(&co1);
    cout << endl;
    area(co1);
    length(&co1);
    s_Area(co1);
    volumn(&co1);
    co2.setH(h);
    show(&co2);
    cout << endl;
    area(co2);
    length(&co2);
    s_Area(co2);
    volumn(&co2);
    return 0;
}

以上三题做法基本相同

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