according to the given UML class diagram youre required to d

according to the given UML class diagram, you’re required to design the following classes:

Package

TwoDayPackage

OvernightPackage

You are also required to write a driver’s program (name it as Assignment7.cpp) to create several objects from above classes and do the relevant computation on them.

Section 3: Program description

3.1 Introduction

Package-delivery services, such as FedEx, DHL and UPS offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages.

Use class Package as the base class of the hierarchy, then include classes

TwoDayPackage and OvernightPackage that derive from Package.

Base class Package should include data members representing the name, address, city, state and ZIP code for both the sender and the recipient of the package, in addition to data members that store the weight (in ounces) and cost per ounce to ship the package.

Package’s constructor should initialize above data members.

Package should provide a public member function calculateCost() that returns a double value indicting the cost associated with shipping the package.

Package’s calculateCost() function should determine the cost by multiplying the weight by the cost per ounce.

Below please find the UML diagram for Package class.

1

Package

#senderName: string #senderAddress: string #senderCity: string #senderState: string #senderZip: int

#recipientName: string #recipientAddress: string #recipientCity: string #recipientState: string #recipientZip: int

#weight: double #costPerOunce: double

+Package(string &sName, string &sAddress, string &sCity, string &sState, int sZIP,

string &rName, string &rAddress, string &rCity, string &rState, int rZIP, double w, double cost)

+getSenderName(): string +getSenderAddress(): string +getSenderCity(): string +getSenderState(): string +getSenderZIP(): int

+getRecipientName(): string +getRecipientAddress(): string +getRecipientCity(): string +getRecipientState(): string +getRecipientZIP(): int

+getWeight(): double +setWeight(double ):void +getCostPerOunce(): double +setCostPerOunce(double ): void

+toString(): string

+calculateCost(): double

Package class

It is a base class, which will be used to derive the following two sub classes later on:

TwoDayPackage

OvernightPackage

Function calculateCost() will need to be override later.

Function toString() will print the package’s info. in the following format.

\ Sender’s Name:\\t\\tJohn Smith

\ Sender’s Address:\\t\\tNo.1 Main St, Phoenix, AZ, 85004

\ \ Recipient’s Name:\\t\\tMary Johnson

2

\ Recipient’s Address:\\t\\t124th St, Boston, MA, 55555 \ \ Weight:\\t\\t8.50 lb

\ Cost:\\t\\t$0.65 per ounce

4) For Package class’s constructor, we provided the local variables’ name to make the initialization clear.

TwoDayPackage class

It is a sub-class of Package class, i.e. it inherits from class Package

It should inherit the functionality of base class Package, but also include a data member that represents a flat fee that the shipping company charges for two-day-delivery service.

TwoDayPackage’s constructor should also receive a value to initialize data member flatFee. During initialization procedure, make sure call Package’s constructor first.

TwoDayPackage should redefine member function calculateCost() so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Package’s calculateCost() function.

Besides the information printed in the toString() function of Package class, the toString() function in TwoDayPackage class will also need to print the following information on screen:

\ Flat Fee:\\t\\t$8.50

Below please find the UML diagram for TwoDayPackage class

TwoDayPackage

-flatFee : double

+TwoDayPackage(string &sName, string &sAddress, string &sCity, string &sState, int sZIP, string &rName, string &rAddress, string &rCity, string &rState, int rZIP, double w, double cost, double flatFee)

+getFlatFee(): double +setFlatFee( double ): void +toString(): string

OvernightPackage class

It is a sub-class of Package class, i.e. it inherits from class Package

It should inherit the functionality of base class Package, but also include a data member that represents an additional fee per ounce charges to the standard cost for overnight-delivery service.

OvernightPackage’s constructor should receive a value to initialize data member overnightFeePerOunce. Make sure call Package’s constructor first.

OvernightPackage should redefine member function calculateCost() so that it computes the shipping cost by adding the overnight fee per ounce to the standard cost per ounce.

3

5) Besides the information printed in the toString() function of Package class, the toString() function in OvernightPackage class will also need to print the following information on screen:

\ Overnight Fee:\\t\\t$0.25 per ounce

Below please find the UML diagram for OvernightPackage class

OvernightPackage

-overnightFeePerOunce : double

+OvernightPackage(string &sName, string &sAddress, string &sCity, string &sState, int sZIP,

string &rName, string &rAddress, string &rCity, string &rState, int rZIP, double w, double cost, double overnightFee)

+getOvernightFeePerOunce(): double +setOvernightFeePerOunce(double ): void +toString(): string

3.2 Programming Instructions

First, you will need to create the following files to represent these classes:

Package.h : this is the header file which declares the Package class

Package.cpp : this is the class implementation file for Package class

TwoDayPackage.h: this is the header file which declares the TwoDayPackage class

TwoDayPackage.cpp: this is the class implementation file for TwoDayPackage class

OvernightPackage.h: this is the header file which declares the OvernightPackage class

OvernightPackage.cpp: this is the class implementation file for OvernightPackage class

Second, you also need to create a driver program Assignment7.cpp that contains a main function. Your main program will do the following:

1) Create an array which contains 3 packages.

Package #1 is a general package which contains the following information inside:

Sender: Lou Brown

Address: 1 Main St, Boston, MA 11111

Recipient: Mary Smith

Address: 7 Elm St, New York, NY 22222

Package weight: 8.5 ounces

Cost per ounce: $3.50

Package #2 is a two day package which contains the following information inside:

Sender: Lisa Klein

Address: 5 Broadway, Somerville, AZ 33333

Recipient: Bob George

Address: 21 Pine Rd, Scottsdale, AZ 44444

Package weight: 10.5 ounces

Cost per ounce: $0.65

Flat Fee: $3.00

4

Package #3 is an overnight package which contains the following information inside:

Sender: Ed Lewis

Address: 2 Oak St, Chandler, AZ 55555

Recipient: Don Kelly

Address: 9 Main St, Denver, CO 66666

Package weight: 12.25 ounces

Cost per ounce: $7.65

Overnight Fee: $0.25 per ounce

Use a for loop to traverse the array, for each package, invoke the 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 as follows:

Package 1

Sender:

Lou Brown

1 Main St

Boston, MA 11111

Recipient:

Mary Smith

7 Elm St

New York, NY 22222

Cost: $29.75

4) Keep track of the total shipping cost for all 3 Packages in the array and display the total cost as follows when the loop terminates.

Total shipping cost: $???.??

Check and Run Your Program by Using Provided Output Test Case

Compare your program’s output with our solution output, namely soluOutput.txt, make sure they are same.

Next save your program’s output as output1.txt, since you will need to submit the two files.

Section 4: Grading Rubric

Student correctly designed the Package.h file [3 pts]

Student correctly implement the Package.cpp file [5 pts]

Student correctly inherits & design the TwoDayPackage.h file [1 pts]

Student correctly implement the TwoDayPackage.cpp file, especially the constructor and correctly override the calculateCost() and toString( )function [2 pts]

5

Student correctly inherits & design the OvernightPackage.h file [1 pt]

Student correctly implement the OvernightPackage.cpp file, especially the constructor and correctly override the calculateCost() and toString( )function [2 pts]

In main(), students correctly created the 3 package objects [1 pt]

The program student submitted compiles, runs, and produces the correct output which matches the test cases [5 pts]

Solution

PROGRAM CODE:

Package.h

/*
* Package.h
*
* Created on: 17-Nov-2016
* Author: kasturi
*/

#ifndef PACKAGE_H_
#define PACKAGE_H_

#include <string>

using namespace std;

class Package
{
public:
   string senderName;
   string senderAddress;
   string senderCity;
   string senderState;
   int senderZip;
   string recipientName, recipientAddress, recipientCity, recipientState;
   int recipientZip;
   double weight;
   double costPerOunce;

   Package();
   Package(string sName, string sAddress, string sCity, string sState, int sZIP,string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost);
   double calculateCost();
   string getSenderName();
   string getSenderAddress();
   string getSenderCity();
   string getSenderState();
   int getSenderZIP();
   string getRecipientName();
   string getRecipientAddress();
   string getRecipientCity();
   string getRecipientState();
   int getRecipientZIP();
   double getWeight();
   double getCostPerOunce();
   void setWeight(double w);
   void setCostPerOunce(double cost);
   string toString();
};


#endif /* PACKAGE_H_ */

Package.cpp

/*
* Package.cpp
*
* Created on: 16-Nov-2016
* Author: kasturi
*/

#include \"Package.h\"

using namespace std;


Package::Package(string sName, string sAddress, string sCity, string sState, int sZIP,string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost)
{
senderName = sName;
senderAddress = sAddress;
senderCity = sCity;
senderState = sState;
senderZip = sZIP;
recipientName = rName;
recipientAddress = rAddress;
recipientCity = rCity;
recipientState = rState;
recipientZip = rZIP;
weight = w;
costPerOunce = cost;
}

double Package:: calculateCost()
{
return costPerOunce*weight;
}
string Package::getSenderName()
{
return senderName;
}
string Package::getSenderAddress()
{
return senderAddress;
}
string Package::getSenderCity()
{
return senderCity;
}
string Package::getSenderState()
{
return senderState;
}
int Package::getSenderZIP()
{
return senderZip;
}
string Package::getRecipientName()
{
return recipientName;
}
string Package::getRecipientAddress()
{
return recipientAddress;
}
string Package::getRecipientCity()
{
return recipientCity;
}
string Package::getRecipientState()
{
return recipientState;
}
int Package::getRecipientZIP()
{
return recipientZip;
}
double Package::getWeight()
{
return weight;
}
double Package::getCostPerOunce()
{
return costPerOunce;
}
void Package::setWeight(double w)
{
weight = w;
}
void Package::setCostPerOunce(double cost)
{
costPerOunce = cost;
}
string Package::toString()
{
return \"\ Sender\'s Name:\\t\\t\" + senderName +
\"\ Sender\'s Address:\\t\\t\" + senderAddress + \", \" + senderCity + \", \" + senderState + \", \" + to_string(senderZip) +
\"\ \ Recipient\'s Name:\\t\\t\" + recipientName +
\"\ Recipient\'s Address:\\t\\t\" + recipientAddress + \", \" + recipientCity + \", \" + recipientState + \", \" + to_string(recipientZip) +
\"\ \ Weight:\\t\\t\" + to_string(weight) +
\"\ Cost:\\t\\t$\" + to_string(costPerOunce) + \"per ounce\";
}

OvernightPackage.h

/*
* OvernightPackage.h
*
* Created on: 17-Nov-2016
* Author: kasturi
*/

#ifndef OVERNIGHTPACKAGE_H_
#define OVERNIGHTPACKAGE_H_

#include \"Package.h\"
#include <string>

using namespace std;

class OvernightPackage : public Package
{
private:
   double overnightFeePerOunce;
public:

   OvernightPackage(string sName, string sAddress, string sCity, string sState, int sZIP, string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost, double overnightFee);
   string getOvernightFeePerOunce();
   void etOvernightFeePerOunce(double fee);
   string toString();
   double calculateCost();
};

#endif /* OVERNIGHTPACKAGE_H_ */

OvernightPackage.cpp

/*
* OvernightPackage.cpp
*
* Created on: 17-Nov-2016
* Author: kasturi
*/

#include \"OvernightPackage.h\"
#include \"Package.h\"
#include <string>

using namespace std;


   OvernightPackage::OvernightPackage(string sName, string sAddress, string sCity, string sState, int sZIP, string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost, double overnightFee)
:Package(sName, sAddress, sCity, sState, sZIP, rName, rAddress, rCity, rState,rZIP, w, cost )
       {
overnightFeePerOunce = overnightFee;
}
string OvernightPackage::toString()
{
string value = Package::toString() + \"\ Overnight Fee:\\t\\t$\" + to_string(overnightFeePerOunce) + \" per ounce\";
return value;
}
double OvernightPackage::calculateCost()
{
   return (overnightFeePerOunce + costPerOunce) * weight;
}

TwoDayPackage.h

/*
* TwoDayPackage.h
*
* Created on: 17-Nov-2016
* Author: kasturi
*/

#ifndef TWODAYPACKAGE_H_
#define TWODAYPACKAGE_H_

#include <string>
#include \"Package.h\"
using namespace std;
class TwoDayPackage : public Package
{
private:
   double flatFee;
public:

   TwoDayPackage(string sName, string sAddress, string sCity, string sState, int sZIP, string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost, double fee);
   double getFlatFee();
   void setFlatFee( double fee);
   string toString();
   double calculateCost();
};


#endif /* TWODAYPACKAGE_H_ */

TwoDayPackage.cpp

/*
* TwoDayPackage.cpp
*
* Created on: 16-Nov-2016
* Author: kasturi
*/

#include \"TwoDayPackage.h\"
#include \"Package.h\"
using namespace std;


TwoDayPackage::TwoDayPackage(string sName, string sAddress, string sCity, string sState, int sZIP, string rName, string rAddress, string rCity, string rState, int rZIP, double w, double cost, double fee)
:Package(sName, sAddress, sCity, sState, sZIP, rName, rAddress, rCity, rState,rZIP, w, cost )
   {
flatFee = fee;
}

double TwoDayPackage::getFlatFee()
{
return flatFee;
}
void TwoDayPackage::setFlatFee( double fee)
{
flatFee = fee;
}
string TwoDayPackage::toString()
{
string value = Package::toString() + \"\ Flat Fee:\\t\\t$\" + to_string(flatFee);
return value;
}

double TwoDayPackage::calculateCost()
{
   return Package::calculateCost() + flatFee;
}

Assignment7.cpp

/*

* Assignment7.cpp

*

* Created on: 17-Nov-2016

* Author: kasturi

*/

#include \"Package.h\"

#include \"OvernightPackage.h\"

#include \"TwoDayPackage.h\"

#include <iostream>

#include <string>

using namespace std;

int main()

{

   double totalCost = 0.00;

   Package **packages = new Package*[3];

   packages[0] = new Package(\"Lou Brown\", \"1 Main St\", \"Boston\", \"MA\", 11111, \"Mary Smith\", \"7 Elm St\", \"New York\", \"NY\", 22222, 8.5, 3.50);

   packages[1] = new TwoDayPackage(\"Lisa Klein\", \"5 Broadway\", \"Somerville\", \"AZ\", 33333, \"Bob George\", \"21 Pine Rd\", \"Scottsdale\", \"AZ\", 44444, 10.5, 0.65, 3.00);

   packages[2] = new OvernightPackage(\"Ed Lewis\", \"2 Oak St\" ,\"Chandler\", \"AZ\", 55555, \"Don Kelly\", \"9 Main St\", \"Denver\", \"CO\", 66666, 12.25, 7.65, 0.25);

   //printing the address information for each sender and recipient

   for(int i=0; i<3; i++)

   {

       cout<<\"Package \"<<i+1<<endl<<\"Sender: \"<<endl;

       cout<<packages[i]->getSenderName()<<endl;

       cout<<packages[i]->getSenderAddress()<<endl;

       cout<<packages[i]->getSenderCity()<<\", \"<<packages[i]->getSenderState()<<\" \"<<packages[i]->getSenderZIP()<<endl;

       cout<<\"Recipient: \"<<endl;

       cout<<packages[i]->getRecipientName()<<endl;

       cout<<packages[i]->getRecipientAddress()<<endl;

       cout<<packages[i]->getRecipientCity()<<\", \"<<packages[i]->getRecipientState()<<\" \"<<packages[i]->getRecipientZIP()<<endl;

       cout<<\"Cost: $\"<<packages[i]->calculateCost()<<endl<<endl;;

       totalCost = totalCost + packages[i]->calculateCost();

   }

   cout<<\"Total shipping cost: $\"<<totalCost;

}

OUTPUT:

Package 1

Sender:

Lou Brown

1 Main St

Boston, MA 11111

Recipient:

Mary Smith

7 Elm St

New York, NY 22222

Cost: $29.75

Package 2

Sender:

Lisa Klein

5 Broadway

Somerville, AZ 33333

Recipient:

Bob George

21 Pine Rd

Scottsdale, AZ 44444

Cost: $6.825

Package 3

Sender:

Ed Lewis

2 Oak St

Chandler, AZ 55555

Recipient:

Don Kelly

9 Main St

Denver, CO 66666

Cost: $93.7125

Total shipping cost: $130.288

according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write
according to the given UML class diagram, you’re required to design the following classes: Package TwoDayPackage OvernightPackage You are also required to write

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site