|write a main program that creates an array of pointers to 6 ShippingContainer objects.|
Since this asks for an array of pointers, which is unusual, it probably means that you will have a maximum of 6 to deal with but you may also have less than 6.[quote=AssignmentThe array should be used to store both the ManualShippingContainer objects and RFIDShippingContainer objects.[/quote]This means you need one array for both kinds. I assume that ManualShippingContainer
are classes that inherit from ShippingContainer
, using polymorphism.[quote=Assignment]Construct the main program to allow the user to decide the number of each type of objects to be stored in the array.[/quote]Aha, just as I thought. You have a cap of 6 total, but it can also be less. Make sure that the combined total of the two kinds is <= 6. If they enter 6 for the first kind you shouldn't need to ask them how many for the second kind, since it must be 0.
|Instantiate all the objects accordingly and demonstrate how each objects behaves differently when the same instructions are given to them.|
Yep, polymorphism. You have to call methods from the context of a generic ShippingContainer
, and C++ will automatically figure out what kind of conainer it actually is and call the correct methods.
|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|
This is something that should be done before you place the instance into the array, when you still can be sure that it is of the type you think it is.
Basic layout of this program:
-create the array of 6 pointers to ShippingContainer
-ask the user how many ManualShippingContainer
s they want over and over until they give an answer less than or equal to six
-if their answer was less than 6, ask them how many RFIDShippingContainer
s they want over and over until the combined total is less than or equal to six
-for each ManualShippingContainer
ask them for the information required to create one and then set the pointer in the array
-for each RFIDShippingContainer
ask them for the information required to create one and then set the pointer in the correct place in the array
-for each ShippingContainer
in the array, call some function to show that the same code has different behavior due to polymorphism
-deallocate the memory you created with new
by using delete
Your current program is close but you should only be using the array of pointers to ShippingContainer