Question

please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you...

please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you!

In this homework, you are going to write a program to represent various types of packages offered by package-delivery services. You need to create an inheritance hierarchy to represent various types of packages with different shipping options and associated costs. The base class is Package and the derived classes are FlatRatePackage and OvernightPackage. The base class Package includes the following attributes: • Sender information: senderName (string), senderAddress (string), senderCity (string), senderState (string) and senderZIPcode (long). • Recipient information: recipName (string), recipAddress (string), recipCity (string), recipState (string) and recipZIPcode (long). • Other package details: label (string), date (string), weight (double), costPerOunce (double), insuranceType (string), and signatureConfirmation (string). The attributes label, date, weight, costPerOunce represent the package label, the date the package is shipped, the package weight, and the standard shipping fee per ounce, respectively. The insuranceType attribute describes the extra package insurance option. A sender can purchase insurance coverage for mailpieces for up to $5,000 to protect against loss or damage. If the sender does not purchase insurance, then insuranceType is set to “none” and no extra charge is incurred. If the sender prefers to insure the package, then there are two options based on the package’s declared value or desired coverage: up to $1,000, or up to $5,000. insuranceType can thus have the values: “none”, “upto1000”, or “upto5000”. The attribute signatureConfirmation describes another extra service. A sender may request that the receiver signs upon receipt of a package, which incurs an additional charge. This attribute can thus have one of two values, either “none” or “sign”. The specialized class FlatRatePackage has four attributes of its own: • type (string), width (double), length (double), and height (double). The attribute type refers to the package type, which could be a “letter”, a “paddedEnvelope”, a “legalEnvelope”, or a “box”. The attributes width, length, and height refer to the package dimensions. The package dimensions are particularly important in deciding if a given mailpiece should be sent in a small box, a medium one, or a large one. The specialized class OvernightPackage has two attributes of its own: • overnightFee (double) and tracking (string). The attribute overnightFee represents an additional fee per ounce charged for overnight-delivery service. The attribute tracking represents an additional service charged for providing detailed tracking information of the package. Its value is set to either “none” if the sender does not want to track the package or “track”, in which case an additional charge will be incurred. Each class must have the following member functions: • a constructor to initialize and validate all the corresponding attributes. For example, you need to ensure that weight, cost, fees all have positive values, and box dimensions are within the dimensions given in the table below. • set and get functions to assign values and retrieve attribute values (as needed) as well as print function to print the package’s attributes on the screen (specialized and inherited), and its shipping cost. • its own calculateCost function that calculates and returns the cost associated with shipping a certain package. The base class Package’s calculateCost function should determine the cost by multiplying the weight by the costPerOunce and adding the insurance and signature confirmation fees if applicable. Signature confirmation costs an additional $2.90. Insurance fees are based on the item’s declared value or insuranceType as shown in the table below: Insurance Type Insurance Fee ($) Upto1000 5.25 Upto5000 5.50 FlatRatePackage should redefine calculateCost function so it calculates the shipping cost based on the package type and dimensions and independent of its weight. A FlatRatePackage’s cost is a flat fee that depends on the package type and dimensions as summarized below. CalculateCost should also take into account extra services costs such as insurance and signature confirmation fees if applicable. Width Length Height Cost ($) Box < 12 < 12 < 5 20.10 Box < 11 < 8 < 5 17.75 Box < 8 < 5 < 2 11.30 PaddedEnvelope 9.45 LegalEnvelope 7.65 Letter 3.20 OvernightPackage should redefine calculateCost function so it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost. CalculateCost should also take into account extra services costs such as insurance, signature confirmation, and tracking fees if applicable. Tracking incurs an additional charge of $5.50 per package. After you design your base and derived classes, you need to design a PackageInventory class that keeps track of all packages sent. The PackageInventory class has the following attributes: vector packages; vector flatRatePackages; vector overnightPackages; The PackageInventory class has a constructor as well as the following member functions: - CreateNewPackage that creates a Package object, pushes it into the packages vector, and displays a message that the package was successfully added. If any package attribute value is not valid, you should not add an object to the vector and should print appropriate error message. - CreateNewOvernight that creates an OvernightPackage object, pushes it into the OvernightPackages vector, and displays a message that the package was successfully added. If any package attribute value is not valid, you should not add an object to the vector and should print appropriate error message. - CreateNewFlatRate that creates a FlatRatePackage object, pushes it into the FlatRatePackages vector, and displays a message that the package was successfully added. If any package attribute value is not valid, you should not add an object to the vector and should print appropriate error message. - PrintAllPackages that prints the details of all packages in the packages vector: sender and receiver information, package label, date, weight, insurance option, signature confirmation requirements if any, and shipping cost. Note: when printing sender and recipient information (name, address, and city), you get extra credit if you print spaces between words. Each new word starts with an uppercase letter. For example: Sender: Lou Brown 1 Main St Boston, MA 11111 Recipient: Mary Smith 7 Elm St New York, NY 22222 Label: FY0002 Mailed on: 12/03/2016 Weight: 8.5 Insurance: none Signature: none Cost: $4.25 - PrintAllFlatRatePackages that prints the details of all packages in the FlatRatePackages vector in a neat fashion: sender and receiver information, package label, date, weight, type, dimensions, insurance option, signature confirmation requirements if any, and shipping cost. - PrintAllOvernightPackages that prints the details of all packages in the OvernightPackages vector in a neat fashion: sender and receiver information, package label, date, weight, insurance option, signature confirmation, tracking option, and shipping cost. - PrintShippedonMonthYear that prints the details of all base and derived packages shipped on a specific month and year. - CalculateTotalCost that calculates and prints the total cost of a specific type of packages. This includes the shipping cost of all packages in a specific vector. - ProcessTransactionFile that opens the transaction file and processes its lines one by one. If the file could not be opened, you should print appropriate message. Note: Make sure to break up your classes into .cpp and .h files and declare any member function that does not modify the attributes as constant. After you design all your classes, you need to write a main program that displays the address information and calculates the shipping costs for several packages. The main program instantiates an object of type PackageInventory and calls a method to read a transaction file and process its commands. Your main should look like this: int main() { PackageInventory inventory; inventory.ProcessTransactionFile("TransactionFile.txt"); CreateNewPackage LouBrown 1MainSt Boston MA 11111 MarySmith 7ElmSt NewYork NY 22222 FY0002 12/03/2016 8.5 0.5 none none CreateNewPackage AmyJohnson 3465RegentsRd SanDiego CA 92130 EdwardJohnes 439NWGreens Fayetteville NY 13066 HG9983 06/03/2016 10 0.7 upto1000 sign CreateNewPackage BrianFlemings 4356NobelDr SanDiego CA 92130 MarySmith 1245ViaLaGitano Poway CA 93064 LM9983 10/09/2016 3 0.3 upto5000 sign PrintAllPackages CreateNewFlatRate JuliaWu 4387StMary Lafayette LA 70504 DanielTessier 234JohnsonSt Lafayette LA 70503 JJ3981 12/30/2015 8.8 0.2 upto1000 sign paddedEnvelope 10 5 1 CreateNewFlatRate JuliaSmith 4587StMary Lafayette LA 70504 JimEdwards 256JohnsonSt Lafayette LA 70503 MJ3981 12/30/2015 5.8 0.2 upto1000 sign LegalEnvelope 10 5 1 CreateNewFlatRate LisaKlein 5Broadway Somerville MA 33333 BobGeorge 21PineRd Cambridge MA 44444 JJ8765 07/20/2014 10.5 0.65 upto1000 sign letter 2 2 0 CreateNewFlatRate JaredBeth 6GenesseeRd Hillsboro OR 97124 AndreaSmith 65SquareBlvd Philadelphia PA 19121 PO0900 01/12/2015 12 1.1 upto1000 none box 5 6 3 return 0; } The transaction file contains several commands and corresponding values that will create new packages and add them to the corresponding vectors, invoke get functions to obtain the address information of the sender and the recipient, then print the two addresses as they would appear on mailing labels. Also, call each Package’s calculateCost member function and print the result. The commands and their formats are: - CreateNewPackage senderName senderAddress senderCity senderState senderZIPcode recipName recipAddress recipCity recipState recipZIPcode label date weight costPerOunce insuranceType signatureConfirmation - CreateNewFlatRate senderName senderAddress senderCity senderState senderZIPcode recipName recipAddress recipCity recipState recipZIPcode label date weight costPerOunce insuranceType signatureConfirmation type length width height - CreateNewOvernight senderName senderAddress senderCity senderState senderZIPcode recipName recipAddress recipCity recipState recipZIPcode label date weight costPerOunce insuranceType signatureConfirmation tracking OvernightFee - PrintAllPackages - PrintAllFlatRatePackages - PrintAllOvernightPackages - PrintShippedonMonthYear month year - CalculateTotalCost specificVector A sample transaction file is shown below. You may use it to test your code: SuzyWalter 8765RegentsRd SanDiego CA 92131 WV4544 12/01/2016 8.2 1.1 none none track 8 PrintAllOvernightPackages PrintShippedonMonthYear 12 2016 PrintShippedonMonthYear 2 2017 CalculateTotalCost packages CalculateTotalCost flatRatePackages CalculateTotalCost overnightPackages MandyDidier 8764CreekViewBlvd Fayetteville NY 13066 7655FrieserDr Bellevue WA 98005 KI0067 02/05/2017 9.3 3 upto1000 none track 5 CreateNewOvernight PrintAllFlatRatePackages CreateNewOvernight EdLewis 2OakSt Boston MA 55555 DonKelly 9MainSt Denver CO 66666 LL1322 03/08/2017 12.25 0.7 none none none 2.0 CreateNewOvernight MaryPalmer 6534SpringburstDr PalmSprings CA 92240 DennisGarcia 8FifthSt Denver CO 66665 UI0900 10/11/2016 20.1 0.8 upto5000 sign track 7 CreateNewOvernight JoeGarcia 4320CaminoDr LaJolla CA 92037 JamieCliff Once done, you need to submit the following: 1. An electronic copy of your source code and executable file. You should place all source codes in a zipped folder and name it based on your first/last name and the assignment number. For example, JoeSmith-A1.zip. You should submit the zipped folder online through cougar website. CreateNewFlatRate CarolynDavis 101DoveSt SanDiego CA 92129 BrianJames 8765HilcrestRd LasVegas NV 89116 ZT6751 09/14/2016 5 0.3 none none box 7 15 CreateNewFlatRate MatthewGarcia 10876PowayRd Poway CA 93064 JennyFox 125BridleRd Manlius NY 13057 BV7800 12/01/2016 17 0.9 upto5000 sign box 10 10 4 CreateNewFlatRate AmeliaPerez 908BrooksAve Houston TX 77001 MichaelBrown 3987BrieSt Beaverton OR 97076 RS1010 12/21/2015 5 0.2 none none box 3 10 5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

packageInventory.cpp

#include "packageInventory.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>

using std::cout;
using std::left;
using std::right;
using std::setw;
using std::setprecision;
using std::fixed;
using std::showpoint;
using std::noshowpoint;
using std::endl;
using std::resetiosflags;
using std::ios;
using std::string;
using std::ifstream;

PackageInventory::PackageInventory()
{
}
void addSpaceyBois(string &thread)
{
   for (int i = 1; i < thread.length(); i++)
   {
       if (thread[i] >= 'A' && thread[i] <= 'Z')
       {
           thread = thread.insert(i, 1, ' ');
           i++;
       }
   }
}
void PackageInventory::CreateNewPackage(string &sName, string &sAddress, string &sCity, const string &sState, const long &sZipCode,
                                       string &rName, string &rAddress, string &rCity, const string &rState, const long &rZipCode,
                                       const string &pLabel, const string &pDate, const double &pWeight, const double &pCost, const string &pInsurance, const string &pSignature)
{
   addSpaceyBois(sName); addSpaceyBois(sAddress); addSpaceyBois(sCity);
   addSpaceyBois(rName); addSpaceyBois(rAddress); addSpaceyBois(rCity);
   Package package(sName, sAddress, sCity, sState, sZipCode,
                    rName, rAddress, rCity, rState, rZipCode,
                   pLabel, pDate, pWeight, pCost, pInsurance, pSignature);
   if (pWeight > 0)
   {
       packages.push_back(package);
       cout << "Standard Package shipping info successfully stored.\n";
   }
   else
   {
       cout << "Error: Can not store standard package information. (Invalid package weight)\n";
   }
}
void PackageInventory::CreateNewOvernight(string &sName, string &sAddress, string &sCity, const string &sState, const long &sZipCode,
                                          string &rName, string &rAddress, string &rCity, const string &rState, const long &rZipCode,
                                          const string &pLabel, const string &pDate, const double &pWeight, const double &pCost, const string &pInsurance, const string &pSignature, const string &track, const double &fee)
{
   addSpaceyBois(sName); addSpaceyBois(sAddress); addSpaceyBois(sCity);
   addSpaceyBois(rName); addSpaceyBois(rAddress); addSpaceyBois(rCity);
       OvernightPackage overnight(sName, sAddress, sCity, sState, sZipCode,
                               rName, rAddress, rCity, rState, rZipCode,
                               pLabel, pDate, pWeight, pCost, pInsurance, pSignature, track, fee);
   if (pWeight > 0)
   {
       overnightPackages.push_back(overnight);
       cout << "Overnight Package shipping info successfully stored.\n";
   }
   else
   {
       cout << "Error: Can not store overnight package information. (Invalid package weight)\n";
   }
}
void PackageInventory::CreateNewFlatRate(string &sName, string &sAddress, string &sCity, const string &sState, const long &sZipCode,
                                       string &rName, string &rAddress, string &rCity, const string &rState, const long &rZipCode,
                                       const string &pLabel, const string &pDate, const double &pWeight, const double &pCost, const string &pInsurance, const string &pSignature, const string &t, const double &len, const double &wid, const double &hei){
   addSpaceyBois(sName); addSpaceyBois(sAddress); addSpaceyBois(sCity);
   addSpaceyBois(rName); addSpaceyBois(rAddress); addSpaceyBois(rCity);

   FlatRatePackage flatrate(sName, sAddress, sCity, sState, sZipCode,
                           rName, rAddress, rCity, rState, rZipCode,
                             pLabel, pDate, pWeight, pCost, pInsurance, pSignature, t, len, wid, hei);
   if (t == "letter" || t == "paddedEnvelope" || t == "legalEnvelope" || t == "box")
   {
       flatRatePackages.push_back(flatrate);
       cout << "Flat Rate Package shipping info successfully stored.\n";
   }
   else
   {
       cout << "Error: Can not store flat rate package information. (Invalid or unknown package type)\n";
   }
}
void PackageInventory::PrintAllPackages() const
{
   cout << "-----------------------------------------\n"
       << "|Standard Packages Prepared for Shipping|\n"
       << "|Total Packages: " << left << setw(3) << packages.size() << right << setw(21) << "|" << endl;
   for (int i = 0; i < packages.size(); i++)
   {
       cout << "-----------------------------------------\n"
           << "Standard Package #" << i + 1 << endl
           << "-----------------------------------------\n"
           << left << setw(12) << "Sender: " << packages[i].getSenderName() << endl
           << left << setw(12) << " " << packages[i].getSenderAddress() << endl
           << left << setw(12) << " " << packages[i].getSenderCity() << ", " << packages[i].getSenderState() << " " << packages[i].getSenderZipCode() << endl
           << left << setw(12) << "Recipient: " << packages[i].getRecipName() << endl
           << left << setw(12) << " " << packages[i].getRecipAddress() << endl
           << left << setw(12) << " " << packages[i].getRecipCity() << ", " << packages[i].getRecipState() << " " << packages[i].getRecipZipCode() << endl
           << left << setw(12) << "Label: " << packages[i].getLabel() << endl
           << left << setw(12) << "Mailed on: " << packages[i].getDate() << endl
           << left << setw(12) << "Weight: " << packages[i].getWeight() << endl
           << left << setw(12) << "Insurance: " << packages[i].getInsuranceType() << endl
           << left << setw(12) << "Signature: " << packages[i].getSignatureConfirmation() << endl
           << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << packages[i].calculateCost() << endl
           << "-----------------------------------------\n";
   }
}
void PackageInventory::PrintAllOvernightPackages() const
{
   cout << "------------------------------------------\n"
       << "|Overnight Packages Prepared for Shipping|\n"
       << "|Total Packages: " << left << setw(3) << overnightPackages.size() << right << setw(22) << "|" << endl;
   for (int i = 0; i < overnightPackages.size(); i++)
   {
       cout << "------------------------------------------\n"
           << "Overnight Package #" << i + 1 << endl
           << "------------------------------------------\n"
           << left << setw(12) << "Sender: " << overnightPackages[i].getSenderName() << endl
           << left << setw(12) << " " << overnightPackages[i].getSenderAddress() << endl
           << left << setw(12) << " " << overnightPackages[i].getSenderCity() << ", " << overnightPackages[i].getSenderState() << " " << overnightPackages[i].getSenderZipCode() << endl
           << left << setw(12) << "Recipient: " << overnightPackages[i].getRecipName() << endl
           << left << setw(12) << " " << overnightPackages[i].getRecipAddress() << endl
           << left << setw(12) << " " << overnightPackages[i].getRecipCity() << ", " << overnightPackages[i].getRecipState() << " " << overnightPackages[i].getRecipZipCode() << endl
           << left << setw(12) << "Label: " << overnightPackages[i].getLabel() << endl
           << left << setw(12) << "Mailed on: " << overnightPackages[i].getDate() << endl
           << left << setw(12) << "Weight: " << overnightPackages[i].getWeight() << endl
           << left << setw(12) << "Insurance: " << overnightPackages[i].getInsuranceType() << endl
           << left << setw(12) << "Signature: " << overnightPackages[i].getSignatureConfirmation() << endl
           << left << setw(12) << "Tracking: " << overnightPackages[i].getTracking() << endl
           << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << overnightPackages[i].calculateCost() << endl
           << "------------------------------------------\n";
   }
}
void PackageInventory::PrintAllFlatRatePackages() const
{
   cout << "------------------------------------------\n"
       << "|Flat Rate Packages Prepared for Shipping|\n"
       << "|Total Packages: " << left << setw(3) << flatRatePackages.size() << right << setw(22) << "|" << endl;
   for (int i = 0; i < flatRatePackages.size(); i++)
   {
       cout << "------------------------------------------\n"
           << "Flat Rate Package #" << i + 1 << endl
           << "------------------------------------------\n"
           << left << setw(12) << "Sender: " << flatRatePackages[i].getSenderName() << endl
           << left << setw(12) << " " << flatRatePackages[i].getSenderAddress() << endl
           << left << setw(12) << " " << flatRatePackages[i].getSenderCity() << ", " << flatRatePackages[i].getSenderState() << " " << flatRatePackages[i].getSenderZipCode() << endl
           << left << setw(12) << "Recipient: " << flatRatePackages[i].getRecipName() << endl
           << left << setw(12) << " " << flatRatePackages[i].getRecipAddress() << endl
           << left << setw(12) << " " << flatRatePackages[i].getRecipCity() << ", " << flatRatePackages[i].getRecipState() << " " << flatRatePackages[i].getRecipZipCode() << endl
           << left << setw(12) << "Label: " << flatRatePackages[i].getLabel() << endl
           << left << setw(12) << "Mailed on: " << flatRatePackages[i].getDate() << endl
           << left << setw(12) << "Weight: " << flatRatePackages[i].getWeight() << endl
           << left << setw(12) << "Type: " << flatRatePackages[i].getType() << endl
           << left << setw(12) << "Dimensions: " << noshowpoint << resetiosflags(ios::fixed) << flatRatePackages[i].getLength() << "x" << flatRatePackages[i].getWidth() << "x" << flatRatePackages[i].getHeight() << endl
           << left << setw(12) << "Insurance: " << flatRatePackages[i].getInsuranceType() << endl
           << left << setw(12) << "Signature: " << flatRatePackages[i].getSignatureConfirmation() << endl
           << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << flatRatePackages[i].calculateCost(flatRatePackages[i].getType(), flatRatePackages[i].getLength(), flatRatePackages[i].getWidth(), flatRatePackages[i].getHeight()) << endl
           << "------------------------------------------\n";
   }
}
void PackageInventory::PrintShippedOnMonthYear(string m, string y) const
{
   string date;
   bool found = false;
   if (m.length() == 1) //Inserts a zero in front of single-digit months since they can be present in our command file. It makes our lives easier. (9/2018 - > 09/2018)
   {
       m = m.insert(0, "0");
   }
   for (int i = 0; i < packages.size(); i++) //Check if any standard packages were shipped on the passed date. Print if true.
   {
       date = packages[i].getDate();
       if (m == date.substr(0, date.find("/", 0)) && y == date.substr(6, date.find('\n', 5)))
       {
           found = true;
           cout << "-----------------------------------------\n"
               << "|Standard Package Shipped in " << setw(2) << m << "/" << setw(4) << y << setw(5) << "|"
                << "\n-----------------------------------------\n"
               << "Standard Package #" << i + 1 << endl
               << "-----------------------------------------\n"
               << left << setw(12) << "Sender: " << packages[i].getSenderName() << endl
               << left << setw(12) << " " << packages[i].getSenderAddress() << endl
               << left << setw(12) << " " << packages[i].getSenderCity() << ", " << packages[i].getSenderState() << " " << packages[i].getSenderZipCode() << endl
               << left << setw(12) << "Recipient: " << packages[i].getRecipName() << endl
               << left << setw(12) << " " << packages[i].getRecipAddress() << endl
               << left << setw(12) << " " << packages[i].getRecipCity() << ", " << packages[i].getRecipState() << " " << packages[i].getRecipZipCode() << endl
               << left << setw(12) << "Label: " << packages[i].getLabel() << endl
               << left << setw(12) << "Mailed on: " << packages[i].getDate() << endl
               << left << setw(12) << "Weight: " << packages[i].getWeight() << endl
               << left << setw(12) << "Insurance: " << packages[i].getInsuranceType() << endl
               << left << setw(12) << "Signature: " << packages[i].getSignatureConfirmation() << endl
               << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << packages[i].calculateCost() << endl
               << "-----------------------------------------\n";
       }
   }
   for (int i = 0; i < overnightPackages.size(); i++) //Check if any overnight packages were shipped on the passed date. Print if true.
   {
       date = overnightPackages[i].getDate();
       if (m == date.substr(0, date.find("/", 0)) && y == date.substr(6, date.find('\n', 5)))
       {
           found = true;
           cout << "-----------------------------------------\n"
               << "|Overnight Package Shipped in " << right << setw(2) << m << "/" << setw(4) << y << setw(4) << "|"
               << "\n-----------------------------------------\n"
               << "Overnight Package #" << i + 1 << endl
               << "-----------------------------------------\n"
               << left << setw(12) << "Sender: " << overnightPackages[i].getSenderName() << endl
               << left << setw(12) << " " << overnightPackages[i].getSenderAddress() << endl
               << left << setw(12) << " " << overnightPackages[i].getSenderCity() << ", " << overnightPackages[i].getSenderState() << " " << overnightPackages[i].getSenderZipCode() << endl
               << left << setw(12) << "Recipient: " << overnightPackages[i].getRecipName() << endl
               << left << setw(12) << " " << overnightPackages[i].getRecipAddress() << endl
               << left << setw(12) << " " << overnightPackages[i].getRecipCity() << ", " << overnightPackages[i].getRecipState() << " " << overnightPackages[i].getRecipZipCode() << endl
               << left << setw(12) << "Label: " << overnightPackages[i].getLabel() << endl
               << left << setw(12) << "Mailed on: " << overnightPackages[i].getDate() << endl
               << left << setw(12) << "Weight: " << overnightPackages[i].getWeight() << endl
               << left << setw(12) << "Insurance: " << overnightPackages[i].getInsuranceType() << endl
               << left << setw(12) << "Signature: " << overnightPackages[i].getSignatureConfirmation() << endl
               << left << setw(12) << "Tracking: " << overnightPackages[i].getTracking() << endl
               << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << overnightPackages[i].calculateCost() << endl
               << "-----------------------------------------\n";
       }
   }
   for (int i = 0; i < flatRatePackages.size(); i++) //Check if any flat rate packages were shipped on the passed date. Print if true.
   {
       date = flatRatePackages[i].getDate();
       if (m == date.substr(0, date.find("/", 0)) && y == date.substr(6, date.find('\n', 5)))
       {
           found = true;
           cout << "-----------------------------------------\n"
               << "|Flat Rate Package Shipped in " << right << setw(2) << m << "/" << setw(4) << y << setw(4) << "|"
               << "\n-----------------------------------------\n"
               << "Flat Rate Package #" << i + 1 << endl
               << "-----------------------------------------\n"
               << left << setw(12) << "Sender: " << flatRatePackages[i].getSenderName() << endl
               << left << setw(12) << " " << flatRatePackages[i].getSenderAddress() << endl
               << left << setw(12) << " " << flatRatePackages[i].getSenderCity() << ", " << flatRatePackages[i].getSenderState() << " " << flatRatePackages[i].getSenderZipCode() << endl
               << left << setw(12) << "Recipient: " << flatRatePackages[i].getRecipName() << endl
               << left << setw(12) << " " << flatRatePackages[i].getRecipAddress() << endl
               << left << setw(12) << " " << flatRatePackages[i].getRecipCity() << ", " << flatRatePackages[i].getRecipState() << " " << flatRatePackages[i].getRecipZipCode() << endl
               << left << setw(12) << "Label: " << flatRatePackages[i].getLabel() << endl
               << left << setw(12) << "Mailed on: " << flatRatePackages[i].getDate() << endl
               << left << setw(12) << "Weight: " << flatRatePackages[i].getWeight() << endl
               << left << setw(12) << "Type: " << flatRatePackages[i].getType() << endl
               << left << setw(12) << "Dimensions: " << noshowpoint << resetiosflags(ios::fixed) << flatRatePackages[i].getLength() << "x" << flatRatePackages[i].getWidth() << "x" << flatRatePackages[i].getHeight() << endl
               << left << setw(12) << "Insurance: " << flatRatePackages[i].getInsuranceType() << endl
               << left << setw(12) << "Signature: " << flatRatePackages[i].getSignatureConfirmation() << endl
               << left << setw(12) << "Cost: " << fixed << showpoint << setprecision(2) << "$" << flatRatePackages[i].calculateCost(flatRatePackages[i].getType(), flatRatePackages[i].getLength(), flatRatePackages[i].getWidth(), flatRatePackages[i].getHeight()) << endl
               << "-----------------------------------------\n";
       }
   }
   if (!found)
   {
       cout << "-----------------------------------------\n"
           << "|No Packages were Shipped in " << right << setw(2) << m << "/" << setw(4) << y << "." << setw(4) << "|"
           << "\n-----------------------------------------\n";
   }
}
void PackageInventory::calculateTotalCost(const string & pT) const
{
   double totalCost = 0.0;
   if (pT == "packages")
   {
       for (int i = 0; i < packages.size(); i++)
       {
           totalCost += packages[i].calculateCost();
       }
       cout << "The total cost of all " << packages.size() << " shipped standard packages is: $" << totalCost << endl;
   }
   if (pT == "overnightPackages")
   {
       for (int i = 0; i < overnightPackages.size(); i++)
       {
           totalCost += overnightPackages[i].calculateCost();
       }
       cout << "The total cost of all " << overnightPackages.size() << " shipped overnight packages is: $" << totalCost << endl;
   }
   if (pT == "flatRatePackages")
   {
       for (int i = 0; i < flatRatePackages.size(); i++)
       {
           totalCost += flatRatePackages[i].calculateCost(flatRatePackages[i].getType(), flatRatePackages[i].getLength(), flatRatePackages[i].getWidth(), flatRatePackages[i].getHeight());
       }
       cout << "The total cost of all " << flatRatePackages.size() << " shipped flat rate packages is: $" << totalCost << endl;
   }
}
void PackageInventory::ProcessShippingFile(const string &fileName)
{
   ifstream fin;
   string command;
   string month, day;
   string packageType;
   string senderName, senderAddress, senderCity, senderState; //Sender Information
   long senderZIPcode; //Sender Information
   string recipName, recipAddress, recipCity, recipState; //Recipient Information
   long recipZIPcode; //Recipient Information
   string label, date, insuranceType, signatureConfirmation, tracking, type; //Package Information
   double weight, costPerOunce, overnightFee, width, length, height; //Package Information
   fin.open(fileName);
   if (!fin)
   {
       cout << "The shipping file \"" << fileName << "\" can not be opened or does not exist.\n";
   }
   else
   {
       cout << "Successfully opened shipping file: \"" << fileName << "\"\n";
       fin >> command;
       while (fin)
       {
           if (command == "CreateNewPackage")
           {
               fin >> senderName >> senderAddress >> senderCity >> senderState >> senderZIPcode
                   >> recipName >> recipAddress >> recipCity >> recipState >> recipZIPcode
                   >> label >> date >> weight >> costPerOunce >> insuranceType >> signatureConfirmation;

               CreateNewPackage(senderName, senderAddress, senderCity, senderState, senderZIPcode,
                               recipName, recipAddress, recipCity, recipState, recipZIPcode,
                               label, date, weight, costPerOunce, insuranceType, signatureConfirmation);
           }
           if (command == "CreateNewOvernight")
           {
               fin >> senderName >> senderAddress >> senderCity >> senderState >> senderZIPcode
                   >> recipName >> recipAddress >> recipCity >> recipState >> recipZIPcode
                   >> label >> date >> weight >> costPerOunce >> insuranceType >> signatureConfirmation
                   >> tracking >> overnightFee;

               CreateNewOvernight(senderName, senderAddress, senderCity, senderState, senderZIPcode,
                   recipName, recipAddress, recipCity, recipState, recipZIPcode,
                   label, date, weight, costPerOunce, insuranceType, signatureConfirmation, tracking, overnightFee);
           }
           if (command == "CreateNewFlatRate")
           {
               fin >> senderName >> senderAddress >> senderCity >> senderState >> senderZIPcode
                   >> recipName >> recipAddress >> recipCity >> recipState >> recipZIPcode
                   >> label >> date >> weight >> costPerOunce >> insuranceType >> signatureConfirmation
                   >> type >> length >> width >> height;

               CreateNewFlatRate(senderName, senderAddress, senderCity, senderState, senderZIPcode,
                                  recipName, recipAddress, recipCity, recipState, recipZIPcode,
                                  label, date, weight, costPerOunce, insuranceType, signatureConfirmation, type, length, width, height);
           }
           if (command == "PrintAllPackages")
           {
               PrintAllPackages();
           }
           if (command == "PrintAllOvernightPackages")
           {
               PrintAllOvernightPackages();
           }
           if (command == "PrintAllFlatRatePackages")
           {
               PrintAllFlatRatePackages();
           }
           if (command == "PrintShippedonMonthYear")
           {
               fin >> month >> day;
               PrintShippedOnMonthYear(month, day);
           }
           if (command == "CalculateTotalCost")
           {
               fin >> packageType;
               calculateTotalCost(packageType);
           }
           fin >> command;
       }
   }
   fin.close();
}

Add a comment
Answer #2

Based on the provided requirements, I will provide an example implementation of the classes

Based on the provided requirements, I will provide an example implementation of the classes Package, FlatRatePackage, OvernightPackage, and PackageInventory in C++.

Here's the implementation:

cpp

#include <iostream>#include <vector>#include <string>#include <iomanip>using namespace std;// Base class Packageclass Package {protected:    // Sender information    string senderName;    string senderAddress;    string senderCity;    string senderState;    long senderZIPcode;    // Recipient information    string recipName;    string recipAddress;    string recipCity;    string recipState;    long recipZIPcode;    // Other package details    string label;    string date;    double weight;    double costPerOunce;    string insuranceType;    string signatureConfirmation;public:    Package(const string& senderName, const string& senderAddress, const string& senderCity, const string& senderState, long senderZIPcode,            const string& recipName, const string& recipAddress, const string& recipCity, const string& recipState, long recipZIPcode,            const string& label, const string& date, double weight, double costPerOunce, const string& insuranceType, const string& signatureConfirmation)            : senderName(senderName), senderAddress(senderAddress), senderCity(senderCity), senderState(senderState), senderZIPcode(senderZIPcode),              recipName(recipName), recipAddress(recipAddress), recipCity(recipCity), recipState(recipState), recipZIPcode(recipZIPcode),              label(label), date(date), weight(weight), costPerOunce(costPerOunce), insuranceType(insuranceType), signatureConfirmation(signatureConfirmation) {    }    // Getters    string getSenderName() const {        return senderName;    }    string getSenderAddress() const {        return senderAddress;    }    string getSenderCity() const {        return senderCity;    }    string getSenderState() const {        return senderState;    }    long getSenderZIPcode() const {        return senderZIPcode;    }    string getRecipName() const {        return recipName;    }    string getRecipAddress() const {        return recipAddress;    }    string getRecipCity() const {        return recipCity;    }    string getRecipState() const {        return recipState;    }    long getRecipZIPcode() const {        return recipZIPcode;    }    string getLabel() const {        return label;    }    string getDate() const {        return date;    }    double getWeight() const {        return weight;    }    double getCostPerOunce() const {        return costPerOunce;    }    string getInsuranceType() const {        return insuranceType;    }    string getSignatureConfirmation() const {        return signatureConfirmation;    }    // Calculate shipping cost    virtual double calculateCost() const {        double cost = weight * costPerOunce;        if (insuranceType == "upto1000")            cost += 5.25;        else if (insuranceType == "upto5000")            cost += 5.50;        if (signatureConfirmation == "sign")            cost += 2.90;        return cost;    }    // Print package details    virtual void printDetails() const {        cout << "Sender: " << senderName << " " << senderAddress << " " << senderCity << ", " << senderState << " " << senderZIPcode << endl;        cout << "Recipient: " << recipName << "


answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as...

    C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of...

  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

  • ***USING JAVA. MUST USE A SWITCH STATEMENT. THANK YOU. Fall 2019 - Homework #3: Shipping Rates...

    ***USING JAVA. MUST USE A SWITCH STATEMENT. THANK YOU. Fall 2019 - Homework #3: Shipping Rates A client has hired your firm to implement their shipping rate rules as a Java program they can easily run. They have provided the following business rules to you. For each category, a cost and shipping time is added, as noted: Box Volume Categories: Category 1: 0.0 to 0.5 cubic feet, adds $5 to cost. Category 2: 0.5 to 2.0 cubic feet, adds $10...

  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

  • please only answer if willing to answer all thank you! A rectangular poster is to contain...

    please only answer if willing to answer all thank you! A rectangular poster is to contain 968 square Inches of print. The margins at the top and bottom of the poster are to be 2 inches, and the margins on the left and right are to be 1 inch What should the dimensions of the poster be so that the least amount of poster is used in smaller value in larger value Need Help 6. [-/2 Points DETA A farmer...

  • Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me e...

    Can someone please help me with this Python code? Thank you in advance, Zybooks keeps giving me errors. Thanks in advance!! This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. (2 pts) item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of...

  • Please use Java to write the program The purpose of this lab is to practice using...

    Please use Java to write the program The purpose of this lab is to practice using inheritance and polymorphism. We need a set of classes for an Insurance company. Insurance companies offer many different types of policies: car, homeowners, flood, earthquake, health, etc. Insurance policies have a lot of data and behavior in common. But they also have differences. You want to build each insurance policy class so that you can reuse as much code as possible. Avoid duplicating code....

  • FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width,...

    FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT