CPSC 131 Spring 2018 Project 2: Package Tracking
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. See TBA688567081000.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.
You are allowed to use the C++ Standard Library containers (such as std::list, and std::list::iterator) for this project.
You are allowed to use or refer to the following implementations:
https://github.com/apanangadan/CSUF-CPSC_131/blob/master/DLinkedList.h
https://github.com/kevinwortman/thedatastructures/blob/master/doubly_linked_list.hh
https://github.com/kevinwortman/thedatastructures/blob/master/doubly_linked_list_example.cc
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 you’re keeping track of whether you’re talking about an address or the object at that address. Remember to use the -> operator!
PackageTracking.h
#ifndef PackageTracking_h
#define PackageTracking_h
#pragma once
#include <iostream>
#include <fstream>
#include <list>
#include <string>
#include <sstream>
#include <stdexcept>
#include <time.h>
#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:
string trackingNo;
list<ShippingStatus> trackingList;
list<ShippingStatus>::iterator listItr;
};
#endif /* PackageTracking_h */
ShippingStatus.h
#ifndef ShippingStatus_h
#define ShippingStatus_h
#pragma once
#include <string>
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:
string status;
string location;
time_t timeUpdated;
};
#endif /* ShippingStatus_h */
- File Format: .cpp, .h, Makefile
- What if I need customized code done for myself? Write to info@libraay.com for booking a custom solution writing exclusively for you
- Development Environment: Linux and C++, Windows and C++