#ifndef PackageTracking_h #define PackageTracking_h #pragma once #include #include #include #include #include #include #include ShippingStatus.h using namespace std;...
Question:
#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 */
#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
}
#ifndef ShippingStatus_h #define ShippingStatus_h
#pragma once
#include
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 */
#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 }
////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT THIS FILE (except for your own testing)
// CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS
////////////////////////////////////////////////////////////////////////////////
#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;
}
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