#include#include#include#include#defineMAXITEM5classCargo{protected:charowner[40];floatweight;chardestination[100];charcontent[2...
#include
#include
#include
#include
#define MAXITEM 5
class Cargo{
protected:
char owner[40];
float weight;
char destination[100];
char content[200];
float charge;
static float weightRange[MAXITEM];
static float chargeRange[MAXITEM];
public:
Cargo(char * owner,float weight,char *destination,char *content);
~Cargo(){};
virtual float calcCharge();
char * getOwner();
float getWeight();
char *getDestination();
char *getContent();
float getCharge();
};
float Cargo::weightRange[MAXITEM]={15.0f,25.0f,45.0f,80.0f,500.0f};
float Cargo::chargeRange[MAXITEM]={0.0f,12.0f,15.0f,20.0f,30.0f};
Cargo::Cargo(char *owner,float weight,char *destination,char *content)
{
strcpy(this->owner,owner);
this->weight=weight;
strcpy(this->destination,destination);
strcpy(this->content,content);
}
float Cargo::calcCharge()
{
int i;
float tw=weight;
float rc=0.0f;
float pw=0.0f;
for(i=0; i
{
if(tw>(weightRange[i]-pw))
{
rc=rc+(weightRange[i]-pw)*chargeRange[i];
tw=weight-weightRange[i];
pw=weightRange[i];
}
else
{
rc=rc+tw*chargeRange[i];
charge=rc;
return charge;
}
}
charge=rc+tw*chargeRange[MAXITEM-1];
return charge;
}
char *Cargo::getOwner()
{
return owner;
}
float Cargo::getWeight()
{
return weight;
}
char *Cargo::getDestination()
{
return destination;
}
char *Cargo::getContent()
{
return content;
}
float Cargo::getCharge()
{
return charge;
}
//class AirCargo definition
class AirCargo: public Cargo
{
private:
int dangerLevel;
char usage[100];
public:
AirCargo(char * owner,float weight,char * destination,char * content,
int dangerLevel,char * usage);
AirCargo():Cargo(" ",0," "," ")
{
}
~AirCargo(){};
float calcCharge();
void init(char *owner,float weight,char *destination,char *content,
int dangerLevel,char * usage);
int getDangerLevel();
char *getUsage();
};
AirCargo::AirCargo(char *owner,float weight,char *destination,char *content,int
dangerLevel,char *usage)
:Cargo(owner,weight,destination,content)
{
this->dangerLevel=dangerLevel;
strcpy(this->usage,usage);
}
float AirCargo::calcCharge()
{
float fee;
fee=Cargo::calcCharge();
if(dangerLevel==1)
fee=fee+getWeight()*5;
charge=fee;
return fee;
}
void Aircago::init(char*owner,float weight,char*destination,char*content,int dangerlevel,char*usage)
每一行讲的都是什么意思?帮帮我啊!
展开