看到 的人请帮帮忙啊

来源:互联网 发布:windows apache 编辑:程序博客网 时间:2024/05/01 17:34

#ifndef BOX_H
#define BOX_H
class Box
{
public:
        Box(double lengthValue=1.0,double widthValue=1.0,double heightValue=1.0);
        void showVolume() const;
        virtual double volume() const;
protected:
        double length;
        double width;
        double height;
};
#endif
#include <iostream.h>
#include "Box.h"


//constructor
Box::Box(double lv,double wv,double hv):length(lv),width(wv),height(hv)
{}

void Box::showVolume() const
{
        cout<<"Box usable volume is "<<volume()<<endl;
}

double Box::volume() const
{
        return length*width*height;
}
#ifndef CARTON_H
#define CARTON_H
#include <string>
#include "Box.h"

class Carton : public Box
{
public:
        //construct ex
        Carton(double lv,double wv,double hv,string material="Cardboard");
        Carton(const Carton& aCarton);
        ~Carton();
        double volume() const;
private:
        string* pMaterial;
};
#endif
#include "Carton.h"
#include <cstring>

Carton::Carton(double lv,double wv,double hv,string material) : Box(lv,wv,hv)
{
        pMaterial = new string (material);
}
Carton::Carton(const Carton& acarton);
{
        length=aCarton.length;
        width=aCarton.width;
        height=aCarton.height;
        pMaterial = new string(*aCarton.pMaterial);
}

Carton::~Carton ()
{
        delete pMaterial;
}

double Carton::volume() const
{
        double vol = (length-0.5)*(width-0.5)*(height-0.5);
        return vol>0.0 ? vol : 0.0;
}
#ifndef TOUGHPACK_H
#define TOUGHPACK_H

#include "Box.h"


class ToughPack : public Box
{
public:
        ToughPack(double lenghValue,double WidthValue,double heightValue);

        double volume() const;
};


#endif
#include "ToughPack.h"

ToughPack::ToughPack(double lVal,double wVal,double hVal):Box(lVal,wVal,hVal){}


double ToughPack::volume() const
{
        return 0.85*length*width*height;
}

#include <iostream.h>
#include "Box.h"
#include "ToughPack.h"
#include "Carton.h"


int main()
{
        Box myBox(20.0,30.0,40.0);
        ToughPack hardcase(20.0,30.0,40.0);
        Carton aCarton(20.0,30.0,40.0);

        cout<<endl;
        myBox.showVolume();
        hardcase.showVolume();
        aCarton.showVolume();
        cout<<endl;

        return 0;
}

错误信息
/test2/carton.h(11) : error C2629: unexpected 'class Carton ('
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(11) : error C2238: unexpected token(s) preceding ';'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2143: syntax error : missing ';' before '*'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2501: 'string' : missing storage-class or type specifiers
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2501: 'pMaterial' : missing storage-class or type specifiers
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.cpp(5) : error C2061: syntax error : identifier 'string'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.cpp(5) : error C2511: 'Carton::Carton' : overloaded member function 'void (double,double,double)' not found in 'Carton'
        f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(7) : see declaration of 'Carton'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.cpp(27) : fatal error C1004: unexpected end of file found
Test2.cpp
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(11) : error C2629: unexpected 'class Carton ('
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(11) : error C2238: unexpected token(s) preceding ';'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2143: syntax error : missing ';' before '*'
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2501: 'string' : missing storage-class or type specifiers
f:/智慧/c++程序/新建文件夹 (2)/test2/carton.h(16) : error C2501: 'pMaterial' : missing storage-class or type specifiers
f:/智慧/c++程序/新建文件夹 (2)/test2/test2.cpp(11) : error C2660: 'Carton::Carton' : function does not take 3 parameters
Error executing cl.exe.