Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction Modern shipping companies keep track of the location of time sensitive deliveries. Tracking numbers are numbers given to packages when they are shipped. Both

Introduction

Modern shipping companies keep track of the location of time sensitive deliveries. Tracking numbers are numbers given to packages when they are shipped. Both senders and receivers can use tracking numbers to view most recent shipping status and trace back to previous status, as shown in the picture above. The first status comes from the company shipping the package. In the example shown in the picture, the first status is Package has left seller facility and is in transit to carrier. The other statuses are scans at various distribution points within the shipper's system. In this project you will write C++ code to model package tracking.

in addition, when asked, your program should keep track of every shipping status and when it was updated. Since we do not know how many updates the shipping will have, we will have a Linked List that will keep track of every status.

You are given a simple text file containing actions: back, forward, or new. If the action is listed as new, the next line contains three items, time, location and status, separated by semicolon. SeeTBA688567081000.txt file for more details. TBA688567081000.txt shows you the example same as in the picture. You are to simulate package tracking based on this text file.

Objective

You are given partial implementations of two classes. ShippingStatus is a class that holds shipping status including location and status of the package, as well as when the status was recorded. The time visited is the number of seconds from the UNIX epoch, 00:00 Jan 1, 1970 UTC. C++ has a variable type that can handle this, named time_t.

PackageTracking is where the bulk of your work will be done. PackageTracking stores a linked list representation of all the status. It will be able to read the history from a text file.

The text file will have 3 basic commands: new, back, and forward. Back and forward will allow users to view the previous status and the next status of a package. New will provide a newly updated status.

You are to complete the implementations of these classes, adding public/private member variables and functions as needed.

Your code is tested in the provided main.cpp.

Source Code Files

You are given skeleton code files with many blank areas. Your assignment is to fill in the missing parts so that the code is complete and works properly when tested.

? ShippingStatus.h and ShippingStatus.cpp: Stores location and status of the package, as well as when the status was recorded.

? PackageTracking.h and PackageTracking.cpp: Stores a linked list representation of all the shipping status for a given package.

? This class contains a method to read item information from a text file. m_readTrackingFile() will read the full tracking chain from a file and follow the commands as specified in the file. Hint: use ifstream, istringstream, getline().

? m_printPreviousUpdates() will print all previous status in the shipping chain when the package was shipped, all the way up to (but not including) the current status that you are viewing.

? m_printFollowingUpdates() will print all status following the current status that you are viewing (inclusive) to the last status in the tracking chain.

? m_printFullTracking() will print all the status updates in the tracking chain.

? Main.cpp: The entry point to the application. The main() function will test the output of your functions. This is already completed but feel free to change it for your own testing (during grading we will use the original main file with more test examples).

Hints

Read code comments for more details of function descriptions.

Start by implementing the ShippingStatus class, then the PackageTracking class. It can be overwhelming working on the PackageTracking class so start with the constructor, then the m_addUpdate() function, then the m_moveBackward()and m_moveForward()functions.

Remember the PackageTracking class will include a linked list for the shipping history. It will also need an iterator or pointer to point to a specific status in the linked list.

Iterators are very similar to pointers. Both iterators and pointers can be tricky. Make sure youre keeping track of whether youre talking about an address or the object at that address. Remember to use the ->operator!

---------------------------------------------------------------------------

ShippingStatus.h

#ifndef ShippingStatus_h

#define ShippingStatus_h
#pragma once
#include
using namespace std;
class ShippingStatus {
public:
ShippingStatus();
ShippingStatus(const string& status, const string& location, const time_t& timeUpdated );
string m_getStatus();
string m_getLocation();
time_t m_getTime();
private:
};
#endif /* ShippingStatus_h */

ShippingStatus.cpp

#include "ShippingStatus.h"
ShippingStatus::ShippingStatus() {
//to be completed
}
ShippingStatus::ShippingStatus(const string& status, const string& location, const time_t& timeUpdated) {
//to be completed
}
string ShippingStatus::m_getStatus(){
//to be completed
}
string ShippingStatus::m_getLocation(){
//to be completed
}
time_t ShippingStatus::m_getTime() {
//to be completed
}

PackageTracking.h

#ifndef PackageTracking_h
#define PackageTracking_h
#pragma once
#include
#include
#include
#include
#include
#include
#include "ShippingStatus.h"
using namespace std;
class PackageTracking {
public:
PackageTracking(const string& strnum);
void m_addUpdate( const string& status, const string& location, const time_t& timeUpdated); // add a new update
bool m_moveBackward();//move iterator one step back in time; return false if not possible (true otherwise)
bool m_moveForward();//move iterator one step forward in time; return false if not possible (true otherwise)
string m_getLocation( );//return the location of the current update
time_t m_getTime( );//return the time of the current update
string m_getStatus( );//return the status of the current update
int m_getNumofUpdate() const; // get the total numbers of shipping status updates
bool m_setCurrent(const time_t& timeUpdated);//set current update to given time; return false if time is not found (true otherwise)
void m_printPreviousUpdates(); //print all previous updates in the shipping chain from beginning, all the way up to (but not including) the current update you are viewing (may not be the most recent update).
void m_printFollowingUpdates();//print all updates from the current update you are viewing to the last update in the tracking chain.
void m_printFullTracking();//print all the status updates in the tracking chain.
//read the full tracking chain from a file and follow the commands as specified in the file
//return false if there is an error reading file (true otherwise)
bool m_readTrackingFile(string fileName);
private:
};
#endif /* PackageTracking_h */

PackageTracking.cpp

#include "PackageTracking.h"
PackageTracking::PackageTracking(const string& strnum) {
//to be completed
}
// add a new update
void PackageTracking::m_addUpdate( const string& status, const string& location, const time_t& timeUpdated){
//to be completed
}
bool PackageTracking::m_moveBackward()//move iterator one step earlier in time
{
//to be completed
}
bool PackageTracking::m_moveForward()//move iterator one step forward in time
{
//to be completed
}
string PackageTracking::m_getLocation( )//return the location of the current update
{
//to be completed
}
time_t PackageTracking::m_getTime( )//return the time of the current update
{
//to be completed
}
string PackageTracking::m_getStatus( )//return the status of the current update
{
//to be completed
}
int PackageTracking::m_getNumofUpdate() const // get the total numbers of shipping status updates
{
//to be completed
}
void PackageTracking::m_printPreviousUpdates() //print all previous updates in the shipping chain when the package was shipped, all the way up to (but not including) the current update you are viewing (may not be the most recent update)
{
//to be completed
}
//print all updates from the current update you are viewing to the last update in the tracking chain
void PackageTracking::m_printFollowingUpdates()
{
//to be completed
}
void PackageTracking::m_printFullTracking()//print all the updates in the tracking chain.
{
//to be completed
}
bool PackageTracking::m_setCurrent(const time_t& timeUpdated)//view an update.
{
//to be completed
}
bool PackageTracking::m_readTrackingFile(string fileName) {
//to be completed
}

TBA688567081000.txt

new
Package has left seller facility and is in transit to carrier;N/A;1515978000
new
Shipment arrived at Amazon facility;Hebron, KENTUCKY US;1516111440
new
Shipment departed from Amazon facility;Hebron, KENTUCKY US;1516188120
new
Shipment arrived at Amazon facility;San Bernardino, CALIFORNIA US;1516366740
new
Shipment departed from Amazon facility;San Bernardino, CALIFORNIA US;1516392780
new
Package arrived at a carrier facility;Chino, US;1516410060
new
Out for delivery;Chino, US;1516441740
new
Delivered;Diamond Bar, US;1516468200
back
back
back
back
forward
forward

Main.cpp

#include
#include
#include
#include
#include
#include "PackageTracking.h"
#include "ShippingStatus.h"
using namespace std;
template
bool testAnswer(const string &nameOfTest, const T& received, const T& expected);
template
bool testArrays(const string& nameOfTest, const T& received, const T& expected, const int& size);
int main() {
// Test only ShippingStatus class
ShippingStatus testStatus01("Package has left seller facility and is in transit to carrier", "N/A", 1515978000);
testAnswer("testStatus01.m_getLocation() test", testStatus01.m_getLocation(), string("N/A"));
testAnswer("testStatus01.m_getStatus() test", testStatus01.m_getStatus(), string("Package has left seller facility and is in transit to carrier"));
testAnswer("testStatus01.m_getTime() test", testStatus01.m_getTime(), time_t(1515978000));
ShippingStatus testStatus02("Shipment arrived at Amazon facility", "Hebron, KENTUCKY US", 1516111440);
testAnswer("testStatus02.m_getLocation() test", testStatus02.m_getLocation(), string("Hebron, KENTUCKY US"));
testAnswer("testStatus02.m_getStatus() test", testStatus02.m_getStatus(), string("Shipment arrived at Amazon facility"));
testAnswer("testStatus02.m_getTime() test", testStatus02.m_getTime(), time_t(1516111440));
ShippingStatus testStatus03("Shipment arrived at Amazon facility", "San Bernardino, CALIFORNIA US", 1516366740);
testAnswer("testStatus03.m_getLocation() test", testStatus03.m_getLocation(), string("San Bernardino, CALIFORNIA US"));
testAnswer("testStatus03.m_getStatus() test", testStatus03.m_getStatus(), string("Shipment arrived at Amazon facility"));
testAnswer("testStatus03.m_getTime() test", testStatus03.m_getTime(), time_t(1516366740));
// Test PackageTracking class
string tmp_strtrackingnumber;//
tmp_strtrackingnumber = "TBA688567081000";
PackageTracking testPackageTracking(tmp_strtrackingnumber);
testPackageTracking.m_addUpdate(testStatus01.m_getStatus(), testStatus01.m_getLocation(), testStatus01.m_getTime());
testPackageTracking.m_addUpdate(testStatus02.m_getStatus(), testStatus02.m_getLocation(), testStatus02.m_getTime());
testPackageTracking.m_addUpdate(testStatus03.m_getStatus(), testStatus03.m_getLocation(), testStatus03.m_getTime());
testPackageTracking.m_setCurrent(testStatus01.m_getTime());
testAnswer("testPackageTracking.m_getLocation()", testPackageTracking.m_getLocation(), string("N/A"));
testAnswer("testPackageTracking.m_getStatus( )", testPackageTracking.m_getStatus( ), string("Package has left seller facility and is in transit to carrier"));
testPackageTracking.m_setCurrent(testStatus02.m_getTime());
testAnswer("testPackageTracking.m_getLocation()", testPackageTracking.m_getLocation(), string("Hebron, KENTUCKY US"));
testAnswer("testPackageTracking.m_getStatus( )", testPackageTracking.m_getStatus( ), string("Shipment arrived at Amazon facility"));
// Test back and forward
testPackageTracking.m_moveForward();
testAnswer("testPackageTracking.m_moveForward()", testPackageTracking.m_getLocation(), string("San Bernardino, CALIFORNIA US"));
testAnswer("testPackageTracking.m_getStatus( )", testPackageTracking.m_getStatus( ), string("Shipment arrived at Amazon facility"));
testAnswer("testPackageTracking.m_getTime( )", testPackageTracking.m_getTime( ), time_t(1516366740));
testPackageTracking.m_moveBackward();
testAnswer("testPackageTracking.m_moveBackward()", testPackageTracking.m_getLocation(), string("Hebron, KENTUCKY US"));
testAnswer("testPackageTracking.m_getStatus( )", testPackageTracking.m_getStatus( ), string("Shipment arrived at Amazon facility"));
testAnswer("testPackageTracking.m_getTime( )", testPackageTracking.m_getTime( ), time_t(1516111440));
// Test PackageTracking reading from a file
PackageTracking testPackageTracking01(tmp_strtrackingnumber);
string tmp_filename = tmp_strtrackingnumber + ".txt";
if (!testPackageTracking01.m_readTrackingFile(tmp_filename)) {
cout << "Failed to read tracking file" << endl;
return (-1);
}
testAnswer("testPackageTracking01.m_getLocation()", testPackageTracking01.m_getLocation(), string("Chino, US"));
testAnswer("testPackageTracking01.m_getStatus( )", testPackageTracking01.m_getStatus( ), string("Package arrived at a carrier facility"));
testAnswer("testPackageTracking01.m_getTime( )", testPackageTracking01.m_getTime( ), time_t(1516410060));
// Test history printing
cout << " Printing all previous updates: ";
testPackageTracking01.m_printPreviousUpdates();
cout << " Printing all following updates: ";
testPackageTracking01.m_printFollowingUpdates();
cout << " Printing Full History: ";
testPackageTracking01.m_printFullTracking();
//system("pause");
return 1;
}
template
bool testAnswer(const string &nameOfTest, const T& received, const T& expected) {
if (received == expected) {
cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;
return true;
}
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
template
bool testArrays(const string& nameOfTest, const T& received, const T& expected, const int& size) {
for(int i = 0; i < size; i++) {
if(received[i] != expected[i]) {
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
}
cout << "PASSED " << nameOfTest << ": expected and received matching arrays" << endl;
return true;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

=+b) Why does the interns suggestion make sense?

Answered: 1 week ago

Question

What changes, if any, are projected for this environment?

Answered: 1 week ago

Question

How have these groups changed within the last three years?

Answered: 1 week ago