Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pseudocode+drawing The goal in this stage is study the problem, and come up with a design to solve the problem. Your design should include: What

Pseudocode+drawing

The goal in this stage is study the problem, and come up with a design to solve the problem. Your design should include:

What are the member variables for the classes and their types

A drawing of the relation between the objects of the two classes

Pseudocode (i.e an informal English outline of the processing steps) of all the member functions

image text in transcribed

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

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.

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!

Given code:

#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;
}

Shipped with AMZL US Tracking ID TBA688567081000 Saturday, January 20 5:10 PM Delivered Diamond Bor, US 9:49 AM Out for delivery Chino, US 1:11 AM Package arrived at a carrier facility Chino, US Friday, January 19 813 PM Shipment departed from Amazon facility Son Bernarding, CALIFORNIA US hipment arrived at Amazon facility Son Bernardina, CALIFORNIA US 12:59 PM Wednesday, January 17 11:22 AM Shipment departed from Amazon facility Hebron, KENTUCKY US Tuesday, January 16 Shipment arrived at Amazon facility Hebron, KENTUCKY US 2:49 PM Monday, January 15 Package has left seller facility and is in transit to carrier Shipped with AMZL US Tracking ID TBA688567081000 Saturday, January 20 5:10 PM Delivered Diamond Bor, US 9:49 AM Out for delivery Chino, US 1:11 AM Package arrived at a carrier facility Chino, US Friday, January 19 813 PM Shipment departed from Amazon facility Son Bernarding, CALIFORNIA US hipment arrived at Amazon facility Son Bernardina, CALIFORNIA US 12:59 PM Wednesday, January 17 11:22 AM Shipment departed from Amazon facility Hebron, KENTUCKY US Tuesday, January 16 Shipment arrived at Amazon facility Hebron, KENTUCKY US 2:49 PM Monday, January 15 Package has left seller facility and is in transit to carrier

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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions