下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序 #include<iostrea

admin2009-01-15  35

问题 下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序
   #include<iostream.h>
   #include<string.h>
   class circle{
       double radius;
       public:
          circle(double r){radius=r;}
       double get_area(){return  3.416*radius*radius;}
   };
   class table{
          double height;
       public:
          table(double h)<height=h;}
          double get_height(){return height;}
       };
   class roundtable:public table,public circle{
          char *color;
       public:
          roundtable(double h,double r,char c[]):  【  】  {
        color=new char[strlen(c) +1];
         【  】;
   };
       char*get_color(){return color;}
   }:
   void main(){
        roundtable rt(0.8,1.0,“白色”);
        cout<<"圆桌的高:"<<rt. get_height()<<end1;
        cout<<"圆桌面积:"<<rt.get_area()<<end1;
        cout<<"圆桌颜色:"<<n.get color()<<end1;
      }

选项

答案circle(r), table(h) strcpy(color, c)

解析
转载请注明原文地址:https://kaotiyun.com/show/Jgkp777K
0

最新回复(0)