Hi看 2023-07-02 22:02 采纳率: 100%
浏览 31
已结题

帮我看看第二个代码与第一个又何差

设计一个圆类circle和一个桌子类table,另设计一个圆桌类roundtable,它是从前两个类派生的,要求输出一个圆桌的高度、面积和颜色等数据。(每个类都要定义带参的构造函数)

#include

using namespace std;

class Circle

{

public:

Circle(double radius)

{



    r=radius;

}

double area()

{

    s=3.14*r*r;

    return s;

}

private:

double r,s;

};

class Table

{

public:

Table(double h)

{

    height=h;

}

double GetH()

{

    return height;

}

private:

double height;

};

class Roundtable:public Circle,public Table

{

public:

Roundtable(double radius,double h,  char *c)

    :Circle(radius),Table(h)

{

    color=new char[strlen(c)+1];

    strcpy(color,c);

}

string GetC()

{

    return color;

}

private:

char *color;

};

int main()

{

Roundtable A(3.6,0.9,"RED");

cout<<"the Basic information of the roundtable : "<<endl;

cout<<"面积 : "<<A.area()<<endl;

cout<<"高度 : "<<A.GetH()<<endl;

cout<<"颜色 : "<<A.GetC()<<endl;

}
这个代码和下面那个代码有啥差别吗?

#include
using namespace std;

class Circle

{

public:

Circle(double radius)

{



    r=radius;

}

double area()

{

    s=3.14*r*r;

    return s;

}

private:

double r,s;

};

class Table

{

public:

Table(double h)

{

    height=h;

}

double GetH()

{

    return height;

}

private:

double height;

};

class Roundtable:public Circle,public Table

{

public:

Roundtable(double radius,double h,  string c)

    :Circle(radius),Table(h)

{

    color=c;

}

string GetC()

{

    return color;

}

private:
string color

};

int main()

{

Roundtable A(3.6,0.9,"RED");

cout<<"the Basic information of the roundtable : "<<endl;

cout<<"面积 : "<<A.area()<<endl;

cout<<"高度 : "<<A.GetH()<<endl;

cout<<"颜色 : "<<A.GetC()<<endl;

}

  • 写回答

3条回答 默认 最新

  • Minuw 2023-07-02 22:05
    关注

    你这代码没贴好

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月10日
  • 已采纳回答 7月2日
  • 创建了问题 7月2日

悬赏问题

  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑