dev-c++代码哪里错了?
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle (double l,double w){length=l,width=w}
double area(){return length*width;}
void display1();
private:
double length;
double width;
};
void Rectangle::display1()
{cout<<"长 :"<<length<<endl;
cout<<"宽 :"<<width<<endl;}
class Cuboid:public Rectangle
{
public:
Cuboid (double L,double w,double h):Rectangle(L,w){high=h,volume=L*w*high }; double vol(){return area()*high;}
void show ();
private:
double high;
double volume;
};
void Cuboid::show()
{
display1();
cout<<"高 :"<<high<<endl;
cout<<"体积 :"<<vol()<<endl;
}
void main()
{
Cuboid cub (10,20,30);
cub.show();
}
程序有两处错
一
Rectangle (double l,double w){length=l,width=w}
正确的
Rectangle (double l,double w){length=l;width=w;}
二
Cuboid (double L,double w,double h):Rectangle(L,w){high=h,volume=L*w*high }; double vol(){return area()*high;}
正确的
Cuboid (double L,double w,double h):Rectangle(L,w){high=h;volume=L*w*high; }; double vol(){return area()*high;}
注意分号
结果
长 :10
宽 :20
高 :30
体积 :6000