FYCEO 2016-01-04 23:55 采纳率: 100%
浏览 2299
已采纳

求大神帮忙改一下,改了好多次了

改了两天了,还是没改好,不知怎么改才好,错的地方有注释

#include
#include
#include
using namespace std;
#define PI 3.1415

class Shape
{
public:
virtual double area()=0;
virtual double volume()=0;//11 18 C:\Users\Administrator\Desktop\未.cpp [Note] virtual double Shape::volume()
virtual double surface()=0;//12 24 C:\Users\Administrator\Desktop\未.cpp [Note] virtual double Shape::surface()
};
class Circle:public Shape//圆形
{
public:
Circle(double r):radius(r){}
virtual double area(){return PI*radius*radius;}
virtual double volume(){return 0;}
virtual double surface(){return 0;}
protected:
double radius;
};
class Cylinder:public Circle//圆柱 //24 7 C:\Users\Administrator\Desktop\未.cpp [Note] Cylinder::Cylinder(const Cylinder&)
{
public:
Cylinder(double r,double h):Circle(r),height(h){} //27 3 C:\Users\Administrator\Desktop\未.cpp [Note] Cylinder::Cylinder(double, double)
virtual double surface(){return PI*radius*2*height+PI*radius*radius*2;}
virtual double volume(){return PI*(radius*2)*height;}
protected:
double height;

};
class Sphere:public Circle//球
{
public:
Sphere(double r):Circle(r){}
double surface(){return 4*radius*radius*PI;}
double volume(){return (4/3)*PI*radius*radius*radius;}
protected:
double radius;

};
class Cone:public Cylinder//圆锥
{
public:
Cone(double r,double h):Cylinder(r),Cylinder(h){}//45 49 C:\Users\Administrator\Desktop\未.cpp [Error] no matching function for call to 'Cylinder::Cylinder(double&)'
double volume(){return (1/3)*(PI*r*r*h);}
double surface(){return PI*r*r+PI*r*sqrt(r*r+h*h);}
protected:
double r,h;

};
class Rectangle:public Shape//长方形 //51 7 C:\Users\Administrator\Desktop\未.cpp [Note] because the following virtual functions are pure within 'Rectangle':
{
public:
Rectangle(double w,double h):width(w),height(h){}
virtual double area(){return width*height;}
protected:
double width,height;
};
class Cuboid//长方体
{
public:
Cuboid(double l,double w,double h):length(l),width(w),height(h){}
double surface(){return 2*(l*w+l*h+w*h);}
double volume(){return l*w*h;}//64 26 C:\Users\Administrator\Desktop\未.cpp [Error] 'l' was not declared in this scope
protected:
double length,width,height;
};
int main()
{
while(true)
{
cout<<"1.圆形"< cout cout cout cout cout cout int choice;
cin>>choice;
system("cls");
if(choice==0)
break;
default://84 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label not within a switch statement
cout << "error" ;
system("pause");
system("cls") ;
switch(choice)
case 1:{double r=0;
cout<<"请输入圆形的半径:";
cin>>r;
Circle circle(r);
cout<<"圆形的面积:"< system("pause");
system("cls") ;
break;
}
case 2:{double w=0,h=0;//98 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label '2' not within a switch statement
cout cout>h;
cout<<"宽:";cin>>w;
Rectangle rectangle(h,w);//102 15 C:\Users\Administrator\Desktop\未.cpp [Error] cannot declare variable 'rectangle' to be of abstract type 'Rectangle'
cout<<"长方形的面积:"< system("pause");
system("cls") ;
break;
}
case 3:{ //108 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label '3' not within a switch statement
double l=0,w=0,h=0;
cout cout>l;
cout<<"宽:";cin>>w;
cout<<"高:";cin>>h;
Cuboid cuboid(l,w,h);
cout<<"长方体的表面积:"< cout system("pause");
system("cls") ;
break;
}
case 4:{//121 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label '4' not within a switch statement
double r=0,h=0;
cout cout>r;
cout<<"高:";cin>>h;
Cylinder cylinder(r,h);
cout<<"圆柱的表面积:"< cout system("pause");
system("cls") ;
break;
}
case 5:{//133 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label '5' not within a switch statement
double r=0,h=0;
cout cout>r;
cout<<"高:";cin>>h;
Cone cone(r,h);
cout<<"圆锥的表面积:"< cout system("pause");
system("cls") ;
break;
}
case 6:{//145 3 C:\Users\Administrator\Desktop\未.cpp [Error] case label '6' not within a switch statement
double r=0;
cout cin>>r;
Sphere sphere(r);
cout<<"圆球的表面积:"<<sphere.area()<<endl;
cout<<"圆球的体积:"<<sphere.volume()<<endl;
system("pause");
system("cls") ;

break;
}

}

}

展开全部

  • 写回答

4条回答 默认 最新

  • ysuwood 2016-01-05 03:43
    关注

    粘贴错误太多,把代码放到代码片里。给你改了一部分:

     class Sphere:public Circle//球 
    {
    public:
        Sphere(double r):Circle(r){}
        double surface(){return 4*radius*radius*PI;}
        double volume(){return (4/3.0)*PI*radius*radius*radius;}//修改
    protected:
        double radius;
    
    };
    class Cone:public Cylinder//圆锥 
    {
    public:
        Cone(double r,double h):Cylinder(r,h){}//修改
        double volume(){return (1/3.0)*(PI*r*r*h);}//修改
        double surface(){return PI*r*r+PI*r*sqrt(r*r+h*h);}
    protected:
        double r,h;
    
    };
    class Rectangle:public Shape//长方形 //51 7 C:\Users\Administrator\Desktop\未.cpp [Note] because the following virtual functions are pure within 'Rectangle':
    {
    public:
        Rectangle(double w,double h):width(w),height(h){}
        virtual double area(){return width*height;}
    protected:
        double width,height;
    };
    class Cuboid//长方体 
    {
    public:
        Cuboid(double l,double w,double h):length(l),width(w),height(h){}
        double surface(){return 2*(length*width+length*height+width*height);}//修改
        double volume(){return length*width*height;}//修改
    protected:
        double length,width,height;
    };
    

    展开全部

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

报告相同问题?

悬赏问题

  • ¥80 有偿!!请懂注册表的翻译解析一下一小段注册表的调整内容
  • ¥15 基于52单片机 交通灯系统
  • ¥15 根据访客ip显示城市名称
  • ¥20 对文档进行操作,有偿 有意向的可以加我v
  • ¥15 brainstorm进行致痫指数分析
  • ¥30 beeline连接hive集群会卡住
  • ¥15 julia语言画表面图
  • ¥15 前端css轮播图效果优化
  • ¥15 如何在已有的土地利用类型图中加入新的地类呢
  • ¥20 TCIA数据库下载报错,请问如何解决
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部