Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using doubly linked list Modern shipping companies keep track of the location of time sensitive deliveries. Tracking numbers are numbers given to packages when they

using doubly linked list

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 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).

//skeleton

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

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 */

here is a DLL scheme to use

#pragma once
#include
using namespace std;
template class DLinkedList; // forward declaration to be used when declaring DNode
template
class DNode { // doubly linked list node
private:
E elem; // node element value
DNode *prev; // previous node in the list
DNode *next; // next node in the list
friend class DLinkedList; // provide SLinkedList access
};
template
class DLinkedList { // a doubly linked list
public:
DLinkedList(); // empty list constructor
~DLinkedList(); // destructor
bool empty() const; // is list empty?
E& front(); // get front element
E& back(); // get back element
void addFront(const E& e); // add to front of list
void addBack(const E& e); // add to back of list
void removeFront(); // remove from front
void removeBack(); // remove from back
int size() const; // list size
private: // local type definitions
int n; // number of items
DNode* header; // header sentinel
DNode* trailer; // trailer sentinel
protected:
void add(DNode* v, const E& e); // insert new node before v
void remove(DNode* v); // remove node v
};
template
DLinkedList::DLinkedList() { // constructor
n = 0; // initially empty
header = new DNode; // create sentinels
trailer = new DNode;
header->next = trailer; // have them point to each other
trailer->prev = header;
}
template
bool DLinkedList::empty() const // is list empty?
{
return (header->next == trailer);
}
template
E& DLinkedList::front() // return front element
{
if (empty()) throw length_error("empty list");
return header->next->elem;
}
template
E& DLinkedList::back() // get back element
{
if (empty()) throw length_error("empty list");
return trailer->prev->elem;
}
template
DLinkedList::~DLinkedList() { // destructor
while (!empty()) removeFront(); // remove all but sentinels
delete header; // remove the sentinels
delete trailer;
}
template
void DLinkedList::add(DNode* v, const E& e) {
DNode* u = new DNode; // create a new node for e
u->elem = e;
u->next = v; // link u in between v
u->prev = v->prev; // ...and v->prev
v->prev->next = u;
v->prev = u;
n++;
}
template
void DLinkedList::addFront(const E& e) // add to front of list
{
add(header->next, e);
}
template
void DLinkedList::addBack(const E& e) // add to back of list
{
add(trailer, e);
}
template
void DLinkedList::remove(DNode* v) { // remove node v
DNode* u = v->prev; // predecessor
DNode* w = v->next; // successor
u->next = w; // unlink v from list
w->prev = u;
delete v;
n--;
}
template
void DLinkedList::removeFront() // remove from font
{
if (empty()) throw length_error("empty list");
remove(header->next);
}
template
void DLinkedList::removeBack() // remove from back
{
if (empty()) throw length_error("empty list");
remove(trailer->prev);
}
template
int DLinkedList::size() const { // list size
return n;
}

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

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions