类的继承
我编了一个类的程序,但是编译时提示以下错误(红颜色标记的),麻烦各位看看。非常感谢:C:\Documents and Settings\wys\桌面\c++\继承.cpp(18) :fatal error C1083: Cannot open include file: 'rectangle.h': No such file or directory
class rectangle
{
private:
double length;
double width;
public:
void setdimension(double l, double w);
double getlength() const;
double getwidth() const;
double area() const;
double perimeter() const;
void print() const;
rectangle();
rectangle(double l, double w);
};
#include <iostream>
#include "rectangle.h"
using namespace std;
void rectangle::setdimension(double l, double w)
{
if(l>0)
length=l;
else
length=0;
if(w>0)
length=w;
else
length=0;
}
double rectangle::getlength() const
{
return length;
}
double rectangle::getwidth() const
{
return width;
}
double rectangle::area() const
{
return length*width;
}
double rectangle::perimeter() const
{
return 2*(length+width);
}
void rectangle::print() const
{
cout<<"length="<<length;
cout<<"width="<<width;
}
rectangle::rectangle(double l, double w)
{
setdimension(l,w);
}
rectangle::rectangle()
{
length=0;
width=0;
}
class boxtype:public rectangle
{
private:
double height;
public:
void setdimension(double l,double w,double h);
double getheight() const;
double area() const;
double volume() const;
void print() const;
boxtype();
boxtype(double l, double w, double h);
};
#include <iostream>
#include "boxtype.h"
using namespace std;
void boxtype::setdimension(double l, double w, double h)
{
rectangle::setdimension(l,w);
if(h>0)
height=h;
else
height=0;
}
double boxtype::getheight() const
{
return height;
}
double boxtype::area() const
{
return 2*(getlength()*getwidth()+getlength()*height+getwidth()*height);
}
double boxtype::volume() const
{
return rectangle::area()*height;
}
void boxtype::print() const
{
rectangle::print();
cout<<"; height="<<height;
}
boxtype::boxtype()
{
height=0;
}
boxtype::boxtype(double l, double w, double h)
:rectangle(l,w)
{
if(h>0)
height=h;
else
height=0;
}
#include <iostream>
#include <iomanip>
#include "rectangle.h"
#include "boxtype.h"
using namespace std;
int main()
{
rectangle myrectangle1;
rectangle myrectangle2(8,6);
boxtype mybox1;
boxtype mybox2(10,7,3);
cout<<fixed<<showpoint<<setprecision(2);
cout<<"line6: myrectangle1: ";
myrectangle1.print();
cout<<endl;
cout<<"line 9: area of myrectangle1:"<<myrectangle1.area()<<endl;
cout<<"line10 : myrectangle2: ";
myrectangle2.print();
cout<<"line 13: area of myrectangle2:"<<myrectangle2.area()<<endl;
cout<<"line 14: mybox1:";
mybox.print();
cout<<endl;
cout<<"lint 17:surface area of mybox1:";
cout<<mybox1.area()<<endl;
cout<<"line 18:volume of mybox1:"<<mybox1.volume()<<endl;
cout<<"line 19: mybox2";
mybox2.print();
cout<<endl;
cout<<"line 22: surface area of mybox2:"<<mybox2.area()<<endl;
cout<<"line 24: volume of mybox2:"<<mybox2.volume()<<endl;
return 0;
}