2.cpp

来自「这源代码是《白领就业指南:visual c++ 6.0 设计师之路》的配套源代码」· C++ 代码 · 共 35 行

CPP
35
字号
#include<iostream.h>
#include<string.h>
class circle
{
       double radius;
public:
        circle(double r)  { radius=r;  }
        double getarea()  { return radius*radius*3.14;  }
};
class table
{
        double height;
public:
        table(double h)  { height=h;  }
        double getheight()  { return height;  }
};
class roundtable : public table,public circle
{
        char *color;
public:
      roundtable(double h, double r, char c[]) : circle (r) , table (h)
      {
          color=new char[strlen(c)+1];
          strcpy (color, c);
      }
        char *getcolor()  { return color;  }
 };
void main()
{   roundtable rt(0.8,1.2,"黑色");
    cout << "圆桌属性数据:" << endl;
    cout << "高度:" <<rt.getheight() << "米"  <<  endl;
    cout << "面积:" <<rt.getarea()  << "平方米"  <<  endl;
    cout << "颜色:" <<rt.getcolor()  <<  endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?