#include "ShippingContainer.h"
#include "ManualShippingContainer.h"
#include "RFIDShippingContainer.h"
int main(){
RFIDShippingContainer theRFIDShippingContainer;
ShippingContainer *theShippingContainer[6] ;
theShippingContainer[0] = new ManualShippingContainer;
theShippingContainer[1] = new ManualShippingContainer;
theShippingContainer[2] = new ManualShippingContainer;
theShippingContainer[3] = new RFIDShippingContainer;
theShippingContainer[4] = new RFIDShippingContainer;
theShippingContainer[5] = new RFIDShippingContainer;
theShippingContainer[0]->setContainerID(5);
theShippingContainer[0]->setManifest("Manual Shipping Manifest");
theShippingContainer[1]->setContainerID(10);
theShippingContainer[1]->setManifest("Manual Shipping Manifest");
theShippingContainer[2]->setContainerID(15);
theShippingContainer[2]->setManifest("Manual Shipping Manifest");
theShippingContainer[3]->setContainerID(20);
theShippingContainer[3]->setManifest("crate of apple");
theShippingContainer[3]->setManifest("crate of apple");
theShippingContainer[3]->setManifest("crate of apple");
theShippingContainer[3]->setManifest("crate of apple");
theShippingContainer[3]->setManifest("crate of oranges");
theShippingContainer[3]->setManifest("crate of oranges");
theShippingContainer[3]->setManifest("crate of oranges");
theShippingContainer[3]->setManifest("crate of bananas");
theShippingContainer[4]->setContainerID(25);
theShippingContainer[4]->setManifest("crate of apples");
theShippingContainer[5]->setContainerID(30);
theShippingContainer[5]->setManifest("crate of oranges");
theShippingContainer[5]->setManifest("crate of oranges");
theShippingContainer[5]->setManifest("crate of apples");
for(int i = 0; i < 5; i++){
int temp = theShippingContainer[i]->getContainerID();
cout << "Container " << temp << " manifest: " << theShippingContainer[i]->getManifest()
<< ", #" << temp << endl;
}
system( "pause" );//System Pause
return 0;
}
in my code ,
the result should be
1 2 3 4 5
rfidContainer.add(“crate of pears”); //add one crate of pears
rfidContainer.add(“crate of apples”); //add one crate of apples
rfidContainer.add(“crate of pears”); //add one crate of pears
At this point, the data structure should be storing a list of two items: crate of apples and crate of pears. The quantity of apples is one and the quantity of pears is two. Override the getManifest function so that it returns a string of all items that is built by traversing the list of items. In the above example, the return string would be “2 crate of pears, 1 crate of apples.”
but mine 1 just contain the craft of pears, it output only 1 craft of pears , but i hope to add like my answer . i already done the coding but don't know where should i add to . can someone help?
#include "ShippingContainer.h"
#include "ManualShippingContainer.h"
class RFIDShippingContainer : public ShippingContainer{
// derived class for RFID method of inventorying the container
private:
string content;// for the content of the item
int quantity;// for the quantity of the added items.
public:
//RFIDShippingContainer (string content, int quantity); // string content represents, for example, "4 crates of apples
RFIDShippingContainer ();// constructors
string getContent();// input string of the content.
int add();// add the item, say add one crate of pears
virtualvoid setManifest( string ); // set the manifest
virtual string getManifest(); // return the string of manifest
};
//RFIDShippingContainer ::RFIDShippingContainer (string content, int quantity){}
RFIDShippingContainer ::RFIDShippingContainer(){
content ="";
quantity = 0;
}
void RFIDShippingContainer :: setManifest( string theManifest ){
content = theManifest;
}
string RFIDShippingContainer :: getContent(){
return content;
}
string RFIDShippingContainer :: getManifest(){
cout<< content<<endl;
return content;
}
int RFIDShippingContainer :: add(){
quantity ++;
return quantity;
}
have to invoke setManifest function to set the contents. For the RFIDShippingContainer objects, you will have to invoke add to set the contents (although, ifthis were real, the contents of the container would “add” themselves via the RFID chips instead of requiring a human to type them in).
erm , from this my add should be a string ?
isnt int add( string )
mean? but i don't know how to add the quantity to compare
for the concept
You haven't really given us a whole lot to go on -
but I will assume that:
setManifest and getManifest functions are actually virtual
functions declared in the base class (ShippingContainer).
The RFIDShippingContainer class looks like it is supposed to hold more than
one item type in it's manifest - so the content member cannot just be a plain string - maybe a vector of strings will be more appropriate.
This means that the quantity member should also be a vetor of integers to match with the content.
[[ I suppose you could use a struct - something like
1 2 3 4 5
struct cargo
{
string content;
int quantity;
};
then you will only need to use one vector - rather than trying to synchronise
two seperate vectors for content and quantity. - that is up to you ]]
The add function should take a string parameter ( for the manifest item - like "crate of pears" or whatever).
the setManifest function could call the add function.
The add function will go through the vector of items already added to the manifest - if the item is already there, then it would just update the quantity - if it is a new type then it should add it to the vector and update the quantity.
@guest , i can know what the process going , but then i not yet learn through vector lesson , so if i build the structure , still got anyway to let setManifest function to compare and call the add function?
and you are right , both of it i declared as virtual function . i just having problem at here , the last part..
#include <iostream>
#include <string>
#ifndef SHIPPINGCONTAINER_H
#define SHIPPINGCONTAINER_H
usingnamespace std;
class ShippingContainer{
private:
int containerID;
public:
//ShippingContainer (int containerID);
ShippingContainer(){
containerID = 0;
}// constructors
void setContainerID( int );//mutator
int getContainerID();//accessor
string IntToString(int i);// convert the ID integers to a string
virtualvoid setManifest( string ) = 0;
virtual string getManifest();//virtual function to output the empty string as the content of the shipping container.
};
void ShippingContainer :: setContainerID( int thecontainerID ){
containerID = thecontainerID;
}
int ShippingContainer :: getContainerID(){
return containerID;
}
string ShippingContainer :: getManifest(){
//virtual function to output the empty string as the content of the shipping container.
//cout<< "";
return("");// return an empty string.
}
#endif
If the RFIDShippingContainer need to be able to hold more than one type of manifest object then the RFIDShippingContainer class is going to need more than one string1 for the content and more than one integer to hold the quantity.
So you will need to use an array, or list, or vector to hold the manifest content names and quantities. Do you know about any of these??
Do you not understand this?
Also, if this is a C++ homework or course question, then post the question as it is seems you are somewhat at a loss.
To model this application, write a base class called ShippingContainer that has a container ID number as an integer. Include member functions to set and access the ID number. Add a virtual function called getManifest that returns an empty string. The purpose of this function is to return the contents of the shipping container.
Create a derived class called ManualShippingContainer that represents the manual method of inventorying the container. In this method, a human simply attaches a textual description of all contents of the container. For example, the description might be “4 crates of apples, 10 crates of pears.” Add a new class variable of type string to store the manifest. Add a function called setManifest that sets this string. Override the getManifest function so that it returns this string.
Create a second derived class called RFIDShippingContainer that represents the RFID method of inventorying the container. To simulate what the RFID chips would compute, create an add function to simulate adding an item to the container. The class should store a list of all added items (as a string) and their quantity using the data structures of your choice. For example, if the add function are invoked three times as follows:
rfidContainer.add(“crate of pears”); //add one crate of pears
rfidContainer.add(“crate of apples”); //add one crate of apples
rfidContainer.add(“crate of pears”); //add one crate of pears
At this point, the data structure should be storing a list of two items: crate of apples and crate of pears. The quantity of apples is one and the quantity of pears is two. Override the getManifest function so that it returns a string of all items that is built by traversing the list of items. In the above example, the return string would be “2 crate of pears, 1 crate of apples.”
Include other necessary functions, constructors, and destructor to all the classes above.
Finally, write a main program that creates an array of pointers to 6 ShippingContainer objects. The array should be used to store both the ManualShippingContainer objects and RFIDShippingContainer objects. Construct the main program to allow the user to decide the number of each type of objects to be stored in the array. Instantiate all the objects accordingly and demonstrate how each objects behaves differently when the same instructions are given to them. For the ManualShippingContainer objects, you will have to invoke setManifest function to set the contents. For the RFIDShippingContainer objects, you will have to invoke add to set the contents (although, if this were real, the contents of the container would “add” themselves via the RFID chips instead of requiring a human to type them in).