CSCI 200 - Fall 2024
Foundational Programming Concepts & Design

Lab 4A - Inventory Management

This lab is due by Wednesday, October 23, 2024, Before Class.
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 of sizes 4 and 2
Warehouse H has 2 boxes (4, 2)

> Made Warehouse C with 1 box of size 3
Warehouse C has 1 boxes (3)

> Used copy assignment operator to copy from H to C, both have 2 boxes of sizes 4 and 2
Warehouse H has 2 boxes (4, 2)
Warehouse C has 2 boxes (4, 2)

> Added box of size 3 to H, H has 3 boxes and C has 2 boxes
Warehouse H has 3 boxes (4, 2, 3)
Warehouse C has 3 boxes (4, 2, 3)

> Adding box of size 7 to C, H has 3 boxes and C has 3 boxes
Warehouse H has 4 boxes (4, 2, 3, 7)
Warehouse C has 4 boxes (4, 2, 3, 7)

> Changed H Box 1 from size 2 to size 15
Warehouse H has 4 boxes (4, 15, 3, 7)
Warehouse C has 4 boxes (4, 15, 3, 7)

> Used copy constructor to construct D from H, both have 3 boxes of sizes 4 15 and 3
Warehouse H has 4 boxes (4, 15, 3, 7)
Warehouse C has 4 boxes (4, 15, 3, 7)
Warehouse D has 4 boxes (4, 15, 3, 7)

> Added box of size 5 to H, H has 4 boxes, C has 3 boxes, and D has 3 boxes
Warehouse H has 5 boxes (4, 15, 3, 7, 5)
Warehouse C has 5 boxes (4, 15, 3, 7, 5)
Warehouse D has 5 boxes (4, 15, 3, 7, 5)

> Added box of size 6 to D, H has 4 boxes and D has 4 boxes
Warehouse H has 6 boxes (4, 15, 3, 7, 5, 6)
Warehouse C has 6 boxes (4, 15, 3, 7, 5, 6)
Warehouse D has 6 boxes (4, 15, 3, 7, 5, 6)

> Changed H Box 2 from size 3 to size 25
Warehouse H has 6 boxes (4, 15, 25, 7, 5, 6)
Warehouse C has 6 boxes (4, 15, 25, 7, 5, 6)
Warehouse D has 6 boxes (4, 15, 25, 7, 5, 6)

> Passing objects to function by value to print (copy constructor and destructor implicitly called)
Warehouse H has 6 boxes (4, 15, 25, 7, 5, 6)
Warehouse C has 6 boxes (4, 15, 25, 7, 5, 6)
Warehouse D 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 a runtime error with the function calls due to the default copy that occurs.

Next, implement the copy constructor to resolve the runtime error and make Warehouse D work.

Finally, implement the copy assignment operator to correct Warehouse C.

When working with the Big 3, consider the abstractions of each process:

CopyConstructor(OTHER) {
  deepCopy(OTHER);
}

CopyAssignmentOperator(OTHER) {
  deallocate(this);
  deepCopy(OTHER);
}

Destructor() {
  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 Wednesday, October 23, 2024, Before Class
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 file(s) and name the zip file L4A.zip. Upload this zip file to Canvas under L4A.

This lab is due by Wednesday, October 23, 2024, Before Class.
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.