Homework 4
In this assignment, you will practice
- Writing code with dynamically allocated arrays of both primitives and objects on the heap.
- Memory management using
new
anddelete
. - Debugging memory management problems with
valgrind
. - Writing code from scratch.
- Code design by writing function “stubs”.
- Writing a Makefile.
- Testing your code (using the CS 70 testing library).
- Experimentally investigating the resource usage of your code.
Quinn's Train
Quinn is a train engineer whose company transports packages. The train visits stations and picks up or delivers packages as it travels.
- If Quinn's train gets completely full of packages, all of the packages need to be moved to a larger train in order to make room for more packages.
- If there is enough unused space in the train, Quinn might decide to move all of those packages to a smaller train.
In this scenario, Quinn must deal with the following financial concerns:
- Customers pay Quinn a shipping fee when they drop off a package.
- Adding a package to the train has a handling cost, which Quinn pays for with labor.
- Moving packages to a new train also has a handling cost, which Quinn also pays for.
Quinn would like you to help design a simulation that takes these concerns into consideration so that the train company can assess the financial trade-offs of different train resizing protocols.
(Pssst! Quinn's business problems are actually metaphors for the computational/resource costs of data structure operations, which we will be focusing on very soon!)
Ooh! Watcha whispering about?!
Don't worry about it. Ready to help Quinn?
Let's do it!!!
Let's Go!
Both team members should accept the assignment:
- Accept Starter Code on GitHub Classroom
- (Create a new team with your new partner. Ideally, name your team in a way that lets us identify you!)
Outline
- Part 1: Written Questions and Partner Contract
- Part 2: Create
car.hpp
- Part 3: Create
car.cpp
- Part 4: Create
train.hpp
- Part 5: Create
train.cpp
- Part 6: Write a Makefile
- Part 7: Implement Car Member Functions
- Part 8: Test Your
Car
Class - Part 9: Implement Train Member Functions
- Part 10: Interactive Experiments
- Part 11: Check Your Submission
Useful Information
Other Resources
You might find Sections 12.1 and 12.2 of the textbook, C++ Primer, 5th Edition, to be helpful.
As always, ask and answer questions on Piazza!
In addition, please review the following pages in the Help Pages:
Grading
Completing this assignment is worth 100 points, and will be graded as follows:
- 6 points: Team Contract
- 18 points: Written Questions
- 5 points: Makefile
- 10 points: Repository Quality (code compiles without warnings, cpplint, no extra/missing files)
- 27 Points: Code Correctness
- 20 Points: Coding Style (clarity, elegance, style)
- 9 Points: Tests of Train Growth Strategies
- 5 Points: Correctly denoting all team members in Gradescope submission
(When logged in, completion status appears here.)