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 .
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
according to the given UML class diagram, you’re required to design .pdf
1. 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
2. +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:ttJohn Smith
Sender’s Address:ttNo.1 Main St, Phoenix, AZ, 85004
Recipient’s Name:ttMary Johnson
2
Recipient’s Address:tt124th St, Boston, MA, 55555 Weight:tt8.50 lb
Cost:tt$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:tt$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)
3. +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:tt$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
4. 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.
5. 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
using namespace std;
class Package
{
public: