(( Q/Make a comment for every codes or explain this codes? )) ########### Packag
ID: 3776074 • Letter: #
Question
(( Q/Make a comment for every codes or explain this codes? ))
########### Package.h #########
#include <string>
using namespace std;
class Package{
public:
string sender_name, sender_address, sender_city, sender_state, sender_ZIP;
string recipient_name, recipient_address, recipient_city, recipient_state, recipient_ZIP;
double weight_in_ounces, cost_per_ounce;
Package();
Package(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost);
};
############## Package.cpp ###########
#include <string>
#include "Package.h"
using namespace std;
Package::Package(){
}
Package::Package(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost){
sender_name = sname;
sender_address = saddress;
sender_city = scity;
sender_state = sstate;
sender_ZIP = sZIP;
recipient_name = rname;
recipient_address = raddress;
recipient_city = rcity;
recipient_state = rstate;
recipient_ZIP = rZIP;
weight_in_ounces = weight;
cost_per_ounce = cost;
}
############ ChildPackage.h #########
#include <string>
#include "Package.h"
using namespace std;
class TwoDayPackage: public Package{
private:
double FlatFee;
public:
TwoDayPackage();
TwoDayPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee);
void setFlatFee(double fee);
double getFlatFee();
double getShippingCost();
};
class OvernightPackage: public Package{
private:
double overnightFeePerOunce;
public:
OvernightPackage();
OvernightPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee);
void setOvernightFeePerOunce(double fee);
double getOvernightFeePerOunce();
double getShippingCost();
};
############## ChildPackage.cpp #############
#include <string>
#include "ChildPackage.h"
using namespace std;
TwoDayPackage::TwoDayPackage(){
}
TwoDayPackage::TwoDayPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee)
: Package(sname, saddress, scity, sstate, sZIP, rname, raddress, rcity, rstate, rZIP, weight, cost){
FlatFee = additional_fee;
}
void TwoDayPackage::setFlatFee(double fee){
FlatFee = fee;
}
double TwoDayPackage::getFlatFee(){
return FlatFee;
}
double TwoDayPackage::getShippingCost(){
return FlatFee + (weight_in_ounces * cost_per_ounce);
}
OvernightPackage::OvernightPackage(){
}
OvernightPackage::OvernightPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee)
: Package(sname, saddress, scity, sstate, sZIP, rname, raddress, rcity, rstate, rZIP, weight, cost){
overnightFeePerOunce = additional_fee;
}
void OvernightPackage::setOvernightFeePerOunce(double fee){
overnightFeePerOunce = fee;
}
double OvernightPackage::getOvernightFeePerOunce(){
return overnightFeePerOunce;
}
double OvernightPackage::getShippingCost(){
return (weight_in_ounces * (cost_per_ounce + overnightFeePerOunce));
}
############# PackageTest.cpp ################
#include <string>
#include <iostream>
#include "ChildPackage.h"
using namespace std;
int main(){
OvernightPackage p1("name1", "address1", "city1", "state1", "zip1", "name2", "address2", "city2", "state2", "zip2", 100, 20, 5);
TwoDayPackage p2("name1", "address1", "city1", "state1", "zip1", "name2", "address2", "city2", "state2", "zip2", 100, 20, 150);
cout << p1.getShippingCost() << endl; // 2500
cout << p2.getShippingCost() << endl; // 2150
return 0;
}
Explanation / Answer
I have also commented on the code.
The code actually takes the senders details and show them the cost of two diffrent type of package.
TwoDayPackage has been created to calculate the cost for the type two day pacakge
where as OverNightPackage has been created to calculate he package cost if send over night.
Each of the class carries the data and fare for the given adddress.
#include <string>
using namespace std;
// creating a class name Package for the details of the package
class Package{
public:
// sender's details
string sender_name, sender_address, sender_city, sender_state, sender_ZIP;
//recipient details
string recipient_name, recipient_address, recipient_city, recipient_state, recipient_ZIP;
// weight of the package
double weight_in_ounces, cost_per_ounce;
Package();
// senders and recievers details
Package(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost);
};
############## Package.cpp ###########
#include <string>
#include "Package.h"
using namespace std;
// creating a class name Package for the details of the package
Package::Package(){
}
// senders and recievers details
Package::Package(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost){
// sender's name
sender_name = sname;
// sender's address
sender_address = saddress;
// sender's city
sender_city = scity;
// sender's state
sender_state = sstate;
// sender's zipcode
sender_ZIP = sZIP;
//recipient's name
recipient_name = rname;
//recipient's address
recipient_address = raddress;
//recipient's city
recipient_city = rcity;
//recipient's state
recipient_state = rstate;
//recipient's zip
recipient_ZIP = rZIP;
//recipient's weight
weight_in_ounces = weight;
// cost per ounce
cost_per_ounce = cost;
}
############ ChildPackage.h #########
#include <string>
#include "Package.h"
using namespace std;
// class TwoDayPackage is created to account for the fee as per the rate
class TwoDayPackage: public Package{
private:
// Fee for the TwoDayPackage
double FlatFee;
public:
TwoDayPackage();
// senders and recievers details
TwoDayPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee);
void setFlatFee(double fee);
double getFlatFee();
double getShippingCost();
};
// class TwoDayPackage is created to account for the fee as per the rate
class OvernightPackage: public Package{
private:
// Fee for the TwoDayPackage
double overnightFeePerOunce;
public:
OvernightPackage();
// senders and recievers details
OvernightPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee);
void setOvernightFeePerOunce(double fee);
double getOvernightFeePerOunce();
double getShippingCost();
};
############## ChildPackage.cpp #############
#include <string>
#include "ChildPackage.h"
using namespace std;
TwoDayPackage::TwoDayPackage(){
}
// senders and recievers details
TwoDayPackage::TwoDayPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee)
: Package(sname, saddress, scity, sstate, sZIP, rname, raddress, rcity, rstate, rZIP, weight, cost){
FlatFee = additional_fee;
}
void TwoDayPackage::setFlatFee(double fee){
// calculate the fee
FlatFee = fee;
}
double TwoDayPackage::getFlatFee(){
//get the fee of the twodayoackage
return FlatFee;
}
double TwoDayPackage::getShippingCost(){
//shipping cost of the twodaypackage
return FlatFee + (weight_in_ounces * cost_per_ounce);
}
OvernightPackage::OvernightPackage(){
}
// senders and recievers details
OvernightPackage::OvernightPackage(string sname, string saddress, string scity, string sstate, string sZIP,
string rname, string raddress, string rcity, string rstate, string rZIP,
double weight, double cost, double additional_fee)
: Package(sname, saddress, scity, sstate, sZIP, rname, raddress, rcity, rstate, rZIP, weight, cost){
overnightFeePerOunce = additional_fee;
}
void OvernightPackage::setOvernightFeePerOunce(double fee){
// get the rate of overnightpackage
overnightFeePerOunce = fee;
}
double OvernightPackage::getOvernightFeePerOunce(){
// return the cost per ounce of the package
return overnightFeePerOunce;
}
double OvernightPackage::getShippingCost(){
// get the shipping cost
return (weight_in_ounces * (cost_per_ounce + overnightFeePerOunce));
}
############# PackageTest.cpp ################
#include <string>
#include <iostream>
#include "ChildPackage.h"
using namespace std;
int main(){
// data of the client and shoe them the cost as per the rate of the two day package and overnight package
OvernightPackage p1("name1", "address1", "city1", "state1", "zip1", "name2", "address2", "city2", "state2", "zip2", 100, 20, 5);
TwoDayPackage p2("name1", "address1", "city1", "state1", "zip1", "name2", "address2", "city2", "state2", "zip2", 100, 20, 150);
cout << p1.getShippingCost() << endl; // 2500
cout << p2.getShippingCost() << endl; // 2150
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.