1 solutions

  • 0
    @ 2025-11-5 15:40:23

    C++ :

    #include<iostream>
    #include<string.h>
    using namespace std;
    
    class circle
    { 
    protected:
        float r;
    public:
        circle(float r0=0)
        { r=r0;}
           double getarea( )
        {return 3.14*r*r;}
       };
    
    class table
    {
    protected:
        float high;
    public:
        table(float high1=0)
        {high=high1;}
        float getheight( )
        {return high;}
        };
    
    class roundtable:public circle,public table
    {
    private:
          string color;
    public:
          roundtable(string color1,float high,float r)
              
              :table(high),circle(r)
          { 
            
            color=color1;
          }
     
    
         string  getcolor( )
          {return color;}
                
        
    };
      
    void display( roundtable &s)
          {
              cout.precision(2);
    		  cout.setf(ios::fixed);
    		  cout<<"圆桌的面积:"<<s.getarea()<<",";
    		  cout<<"高度:"<<s.getheight()<<",";
              cout<<"颜色:"<<s.getcolor()<<"。"<<endl;
          }
    int main()
    {   float r,h;
        char color[10];
       while( cin>>r>>h>>color)
       {roundtable   rt(color,h,r);
       display(rt);}
       return 0; 
    }
    
    • 1

    Information

    ID
    17028
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By