Answer:
See explaination
Explanation:
#include <iostream>
#include <string.h>
using namespace st d;
class Package
{
protected:
//sender properities
char sname[10],saddress[50],scity[20],sstate[20];
long int szip;
//Receiver properities
char rname[10],raddress[50],rcity[20],rstate[20];
long int rzip;
//additonal datamembers
float weight,cost;
public:
Package() //Default constructor
{
strcpy(sname,"");strcpy(saddress,"");strcpy(scity,"");
strcpy(sstate,"");szip=0;
strcpy(rname,"");strcpy(raddress,"");strcpy(rcity,"");
strcpy(rstate,"");rzip=0;
weight=cost=0;
}
Package(char sn[10],char sa[50],char sc[20],char ss[20],long int sz,char rn[10],char ra[50],char rc[20],char rs[20],long int rz,float w,float c) //Constructor with parameter
{
strcpy(sname,sn);strcpy(saddress,sa);strcpy(scity,sc); //copying each parameter value to data member
strcpy(sstate,ss);szip=0;
strcpy(rname,rn);strcpy(raddress,ra);strcpy(rcity,rc);
strcpy(rstate,rs);rzip=0;
weight=w;cost=c;
}
float calculateCost() //calculating cost
{
return weight*cost;
}
};
class TwoDayPackage:public Package //Inheritance
{
float flatfee;
public:
TwoDayPackage(char sn[10],char sa[50],char sc[20],char ss[20],long int sz,char rn[10],char ra[50],char rc[20],char rs[20],long int rz,float w,float c,float ff) //Constructor with parameter
{
Package(sn,sa,sc,ss,sz,rn,ra,rc,rs,rz,w,c); //calling super class constructor
flatfee=ff; //copy last parameter
}
float calculateCost() //redefined calculateCost function
{
return (weight*cost)+flatfee; //return total cost
}
};
class OverNightPackage:public Package //Inheritance
{
float addfee;
public:
OverNightPackage(char sn[10],char sa[50],char sc[20],char ss[20],long int sz,char rn[10],char ra[50],char rc[20],char rs[20],long int rz,float w,float c,float a f) //constructor with parameter
{
Package(sn,sa,sc,ss,sz,rn,ra,rc,rs,rz,w,c); //calling super class constructor
addfee=a f; //copy last parameter
}
float calculateCost() //redefined calculateCost function
{
return (weight*cost)+addfee; //calculating total cost
}
};
int main()
{
Package package1("lou brown","1 main st","boston","ma",11111,"mary smith","7 elm st","new york","ny",22222,8.5,0.5); //creating objects
TwoDayPackage package2("lisa klein", "5 broadway", "somerville", "ma", 33333, "bob george", "21 pine rd", "cambridge", "ma", 44444, 10.5, .65, 2.0 );
OverNightPackage package3 ("ed lewis", "2 oak st", "boston", "ma", 55555, "don kelly", "9 main st", "denver", "co", 66666, 12.25, .7, .25 );
cout<<"\nPackage Cost : "<<package1.calculateCost(); //calling each cost
cout<<"\nTwoDay Package Cost : "<<package2.calculateCost();
cout<<"\nOvernight Package Cost : "<<package3.calculateCost();
return 0;
}