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:UsersAdministratorDesktop未.cpp [Note] virtual double Shape::volume()
virtual double surface()=0;//12 24 C:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.cpp [Note] Cylinder::Cylinder(const Cylinder&)
{
public:
Cylinder(double r,double h):Circle(r),height(h){} //27 3 C:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.cpp [Error] case label '2' not within a switch statement
cout
cout>h;
cout<<"宽:";cin>>w;
Rectangle rectangle(h,w);//102 15 C:UsersAdministratorDesktop未.cpp [Error] cannot declare variable 'rectangle' to be of abstract type 'Rectangle'
cout<<"长方形的面积:"<
system("pause");
system("cls") ;
break;
}
case 3:{ //108 3 C:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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:UsersAdministratorDesktop未.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;
};

解决方案二:

你这个改是要怎么改,都不讲清楚,谁知道怎么弄

解决方案三:

就是有错误,派生类哪里,搞了好久都搞不了

解决方案四:

你把编译器提示错误的地方标出来,减少其他回答者的工作量。

时间: 2024-11-07 22:00:32

c++-求大神帮忙改一下,改了好多次了的相关文章

c++ opencv 分裂合并-求大神帮忙把代码改成调用opencv库的,谢谢。

问题描述 求大神帮忙把代码改成调用opencv库的,谢谢. include using namespace std; #include //需要使用堆栈,对堆栈进行操作 #include "conio.h" include "viLib.h" // 包含头文件 pragma comment( lib, "viLib.lib" ) // 包含viLib.lib库 include "viImage.h" // 包含头文件 prag

client发的请求接收返回信息时用send来接收,其余的由receive来接收,怎么改?求大神帮忙

问题描述 client发的请求接收返回信息时用send来接收,其余的由receive来接收,怎么改?求大神帮忙 sever的请求都友client的receive来接收,client发的请求接收返回信息时用send来接收,怎么改下?求大神帮忙,我只会大概写了下代码,菜鸟急需用! package test; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; impo

编程-跪求大神帮忙看下代码,错了不晓得怎么改哦

问题描述 跪求大神帮忙看下代码,错了不晓得怎么改哦 switch (uMsg) { case WM_CHAR: char szChar[20]; sprintf(_T(szChar),_T( "char code is %d"), wParam); 错误 1 error C2065: "LszChar": 未声明的标识符 IntelliSense: "const wchar_t *" 类型的实参与 "const char *"

游戏-求大神~帮忙改一下。把这串代码改成函数的方式(问题是:用C语言函数制作石头剪刀布)

问题描述 求大神~帮忙改一下.把这串代码改成函数的方式(问题是:用C语言函数制作石头剪刀布) #include #include #include #include void printMenu(void) { printf("tt -------------------------------------------n"); printf("tt| 石头剪刀布游戏 |n"); printf("tt| ---------------------------

select-年龄段查询,请大神帮忙看看怎么改

问题描述 年龄段查询,请大神帮忙看看怎么改 SELECT COUNT(*) renshu CASE WHEN AGE <= 10 THEN '1' WHEN AGE > 10 AND AGE <= 20 THEN '2' WHEN AGE > 20 AND AGE <= 30 THEN '3' WHEN AGE > 30 AND AGE <= 40 THEN '4' WHEN AGE > 40 AND AGE <= 50 THEN '5' WHEN A

求大神将下面递归算法改为非递归算法,万分感谢

问题描述 求大神将下面递归算法改为非递归算法,万分感谢 public void void processFilePath(String sourceDir) { File file = new File(eachSource); if (file.isDirectory()) { for (File each : file.listFiles()) { processFilePath(each.getAbsolutePath()); } } else if (file.getAbsolutePa

ligertree 求大神-ligertree 求大神帮忙解答

问题描述 ligertree 求大神帮忙解答 怎样让ligertree子节点如图片中一样只在点击黑框部分时才可有反应? 解决方案 {求大神帮忙!!!!!!} 解决方案二: 那你要改源代码了,他那个直接点击li容器也会增加选中样式 修改ligeruiV1.2.5SourcelibligerUIjsplugins里面的ligerTree.js, g.tree.click(function (e)这个事件里面,大概在1083这行增加一句判断是点击了文字才执行添加选中样式 if (!$(obj).has

注册表-我想载图片的打开方式那出现我自己写的软件,求大神帮忙?

问题描述 我想载图片的打开方式那出现我自己写的软件,求大神帮忙? 我看网上说的修改注册表,可是我怎么找不到啊,感觉我的这个跟大家的怎么不一样,难道是win10的原因吗?网上说要找到指定类型下的shell下的command,我这里怎么没有啊...求大神帮忙 解决方案 不需要改注册表,选择一个图片文件,点右键,打开方式,然后选择你的程序,勾选下面使用用这个程序打开.

求大神帮忙看看这段代码的问题在哪,求修改一下

问题描述 求大神帮忙看看这段代码的问题在哪,求修改一下 10C 这是题目,代码如下: #include#includeusing namespace std; class People{public: People(const string&NOconst string&nameconst string&sexconst string&IDNOconst string&Birthday); virtual void show()=0;protected: strin