程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c++-求大神幫忙改一下,改了好多次了

c++-求大神幫忙改一下,改了好多次了

編輯:編程綜合問答
求大神幫忙改一下,改了好多次了

改了兩天了,還是沒改好,不知怎麼改才好,錯的地方有注釋

#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;
}

}

}

最佳回答:


粘貼錯誤太多,把代碼放到代碼片裡。給你改了一部分:

 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;
};
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved