This lab is due by Friday, June 09, 2023, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
It's now time to complete the Warehouse example. Download the warehouse starter pack. The program will build out of the box, but not as perhaps expected. View the initial output below:
Made Warehouse H with 2 boxes
H: Warehouse has 2 boxes (4, 2)
Made Warehouse C with 1 box
C: Warehouse has 1 boxes (3)
Using copy assignment operator to copy from H to C, both have 2 boxes
H: Warehouse has 2 boxes (4, 2)
C: Warehouse has 2 boxes (4, 2)
Adding to H, H has 3 and C has 2
H: Warehouse has 3 boxes (4, 2, 3)
C: Warehouse has 3 boxes (4, 2, 3)
Adding to C, H has 3 and C has 3
H: Warehouse has 4 boxes (4, 2, 3, 7)
C: Warehouse has 4 boxes (4, 2, 3, 7)
Changing H Box 1 from size 3 to size 15
H: Warehouse has 4 boxes (4, 15, 3, 7)
C: Warehouse has 4 boxes (4, 15, 3, 7)
Using copy constructor to make D from H, both have 3 boxes
H: Warehouse has 4 boxes (4, 15, 3, 7)
D: Warehouse has 4 boxes (4, 15, 3, 7)
Adding to H, H has 4 and D has 3
H: Warehouse has 5 boxes (4, 15, 3, 7, 5)
D: Warehouse has 5 boxes (4, 15, 3, 7, 5)
Adding to HD H has 4 and D has 4
H: Warehouse has 6 boxes (4, 15, 3, 7, 5, 6)
D: Warehouse has 6 boxes (4, 15, 3, 7, 5, 6)
Changing H Box 2 from size 4 to size 25
H: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
D: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
The problems occur after we copy Warehouse H to another Warehouse. A modification to one causes a modification of the other. This is an indicator of the shallow copy that is occurring.
The Big 3
Your task is to override the Big 3 on the Warehouse
class. Each should do as follows:
- Copy Constructor - deep copy the other Warehouse: allocate a new vector and allocate & insert new Boxes into the vector
- Copy Assignment Operator - deep copy the other Warehouse: deallocate all boxes within the vector, allocate & insert new Boxes into the vector
- Destructor - deallocate all boxes within the vector, deallocate the vector
Hints
When working with the Big 3, consider the abstractions of each process:
CopyConstructor(OTHER) {
deepCopy(OTHER);
}
CopyAssignmentOperator(OTHER) {
deallocate(this);
deepCopy(OTHER);
}
Destrutor() {
deallocate(this);
}
Therefore, it is helpful to split those subtasks into private helper functions on the class.
Lab Submission
Submit your Warehouse.h, Warehouse.cpp
file(s).
You will submit your solution to this lab with the rest of Set4. Detailed instructions for doing this are posted in Assignment 4.
This lab is due by Friday, June 09, 2023, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.