CSCI 200 - Fall 2023
Foundational Programming Concepts & Design

Lab 4A - Inventory Management

This lab is due by Tuesday, October 31, 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.

Jump To: Rubric Submission

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 2 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)
C: 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)
C: 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)
C: 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 3 to size 25
H: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
C: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
D: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)

Passing objects to function by value to print (copy constructor and destructor implicitly called)
Function warehouse: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
Function warehouse: Warehouse has 6 boxes (4, 15, 25, 7, 5, 6)
Function warehouse: 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:


Hints


You should first implement the destructor to ensure your deallocation works on its own. This will initially result in an error with the function calls due to the default copy that occurs.

Next, implement the copy methods to resolve the remaining errors.

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.


Grading Rubric


Your submission will be graded according to the following rubric:

PointsRequirement Description
0.70Fully meets specifications
0.15Submitted correctly by Tuesday, October 31, 2023, 11:59 PM
0.15Best Practices and Style Guide followed
1.00Total Points


Lab Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

Zip together your Warehouse.h, Warehouse.cpp files and name the zip file L4A.zip. Upload this zip file to Canvas under L4A.

This lab is due by Tuesday, October 31, 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.