§1 Task #
The inventory software has been instrumental in helping the bookstore owner prioritize tasks. Now, the owner is expanding the bookstore to offer a wider range of products, including children’s books, games, cookbooks, and graphic novels. Additionally, they plan to integrate your code with an existing user interface, so your code will have to be refactored to be able to integrate with external code.
§2 Info #
For this project, you will continue working with the code you wrote for project 2. You are free to refactor any part of your code, including restarting from scratch if you prefer. You have the flexibility to implement this project in any way that meets the rubric requirements. Like the previous project, your grade will be based solely on your ability to fulfill the requirements.
You will need to support new inventory types and ensure all items can integrate with external code. Inheritance or interfaces will be required for this process. **You will not be writing a main() function in this project, you will only be writing functionality for external code to “hook” into.
You will need to use classes for your inventory objects, and you may not import any external libraries that are not already included in the standard library (this would include libraries downloaded from the internet such as boost or sqlite), otherwise you are free to use any C++ features and standard libraries in your implementation.
Be aware that your source code will be shown to the rest of the class, as we will perform a “code review” of your project implementation.
This project will be accompanied by a short write up, you will be asked to write briefly about what problems you encountered, and why you choose the approach you implemented.
You will not have an opportunity to resubmit your project once graded, However you can ask questions or share code with me before submission. Please reach out if you are having trouble. This project will be the most complex yet, I suggest starting at least a few days before the due date so that you have time to work on it and opportunity to reach out for help.
§3 Guidelines #
You may use a single file or multiple files for your source code.
You may use any approach to represent/store the inventory objects, this could include nested classes, arrays, vectors, lists, etc. Your inventory objects need to be able to implement the ISellable and IPrintable interfaces (described below), this will require the use of classes.
You will need to implement new data importers for 4 new object types. Some of these new items support unique metadata.
New Items:
- Children’s Books: contains unique info for the
Target Ageof the book, this is a string in the format:<AGE>-<AGE>e.g.3-6. - Puzzles & Games: contains
Typeinformation specifying the type of game/puzzle (sudoku, crosswords, etc…). - Cookbooks: contains
Cuisine Typeinformation (Italian, Mexican, Mediterranean, etc.) - Graphic Novels (no new metadata)
The specific list of metadata supported by each new item is listed in the csv header line for each type (line 1). You will need to create new data importer functions like your existing code for importing Books and Magazines.
I would suggest utilizing polymorphism to maximize code reuse in your program. You technically could implement separate functionality for every single inventory type, but this approach would require massive amount of redundant code.
§4 New Features #
Here is list of features that you will need to implement:
- The bookstore now sells several new items, each type is loaded from their respective csv files (e.g. children’s Books are loaded from
childrens-books.csv). The metadata attributes are listed in the csv header line (line 1) of each file, use that to understand how to structure your data loading code. The new items are:
Children's BooksPuzzles & GamesCookbooksGraphic Novels
All items must have unique
ID’s, the method of generating unique ID’s is up to you, but theIDfor every item must remain consistent across multiple program runs. This means you should avoid using randomly generated ID’s without a consistent seed.All items must implement the
ISellableandIPrintableinterfaces:
// Any object that can be sold must implement this interface.
class ISellable {
public:
// getCurrentPrice returns the current price of the item
virtual float getCurrentPrice() const = 0;
// sell performs a single "sale" of an item, and returns true if the sale was successful
// this will return false if the sale fails due to insufficient number of items in inventory
virtual bool sell() = 0;
virtual ~ISellable() = default;
};
// Any object that can be printed to the console must implement this interface.
class IPrintable {
public:
// Returns all attributes of the object.
virtual std::string formatFullInfo() const = 0;
// Returns a limited set of information for the object.
virtual std::string formatShortInfo() const = 0;
virtual ~IPrintable() = default;
};
These interfaces will be utilized by external code.
- You must be able to print informational output for all items in the following format:
IDfollowed byTYPE, followed by all metadata in the same order as the provided csv file, separated by|characters.
- Long-Form:
- Books:
ID: 1 | Type: Book | Title: To Kill a Mockingbird | Author: Harper Lee | Price: $10.99 | Year Published: 1960 | Page Count: 281 | Genre: Fiction | Summary: A novel about racial injustice in the Deep South. | Edition: hardcover | Copies: 1 - Magazines:
ID: 18 | Type: Magazine | Title: Culinary Trends | Edition: 12th | Issue: 78 | Year Published: 2023 | Month Published: October | Price: $5.49 | Page Count: 96 | Genre: Cooking | Summary: Exploring innovative recipes and the future of plant-based cuisine around the world. | Copies: 5 - Children’s Books:
ID: 42 | Type: Children's Book | Title: The Magical Forest | Author: Lily Harper | Price: $12.99 | Year Published: 2018 | Page Count: 120 | Genre: Fantasy | Summary: A young girl discovers a magical forest and learns the secrets of talking animals. | Edition: First | Target Age: 8-10 | Copies: 5 - Puzzles & Games:
ID: 127 | Type: Puzzle/Game Book | Title: Challenging Sudoku Vol. 1 | Author: Barbara Williams | Price: $15.94 | Year Published: 2007 | Page Count: 159 | Genre: Mind Games | Type: Riddles | Summary: A delightful collection of word and logic puzzles. | Edition: 1 | Copies: 9 - Cookbooks:
ID: 63 | Type: Cookbook | Title: The Joy of Italian Cooking | Author: Maria Bianchi | Price: $29.99 | Year Published: 2018 | Page Count: 320 | Genre: Regional Cuisine | Cuisine Type: Italian | Summary: A collection of authentic Italian recipes from pasta to dessert that brings the flavors of Italy to your kitchen. | Edition: 2 | Copies: 5 - Graphic Novels:
ID: 84 | Type: Graphic Novel | Title: The Shadow Chronicles | Author/Illustrator: Lena Wolfe | Price: $19.99 | Year Published: 2021 | Page Count: 210 | Genre: Fantasy | Art Style: Dark Grayscale | Summary: A young warrior must confront ancient forces to save her world from a growing darkness. | Edition: 1st | Copies: 2
- Books:
- Short-Form:
- Books:
Type; Title; Author; Year Published; CopiesBook; To Kill a Mockingbird; Harper Lee; 1960; 1 - Magazines:
Type; Title; Edition; Issue; Year Published; CopiesMagazine; Culinary Trends; 12th; 78; 2023; 5 - Children’s Books:
Type; Title; Author; Year Published; CopiesChildren's Book; The Magical Forest; Lily Harper; 2018; 5 - Puzzles & Games:
Type; Title; Edition; Author; Year Published; CopiesPuzzle/Game Book; Challenging Sudoku Vol. 1; 1; Barbara Williams; 2007; 9 - Cookbooks:
Type; Title; Author; Edition; Year Published; CopiesCookbook; The Joy of Italian Cooking; Maria Bianchi; 2; 2018; 5 - Graphic Novels:
Type; Title; Author; Edition; Year Published; CopiesGraphic Novel; The Shadow Chronicles; Lena Wolfe; 1st; 2021; 2
- Books:
- You need to be able to store all items in a single iterable data structure, this may be a list, vector, map, or any other standard library container. This list will be used to call a printing function on all items. This single data structure will be used to print the full info of every item, it will be utilized in code like this:
for (auto& item : allItems)
{
item.printFullInfo();
}
This will require implementing all items using a shared base class (inheritance) or using interfaces (composition) to enable storing all items together in a single container.
- New search/filtering criteria:
- Able to list items by type
- Able to search all items containing specific text in title or summary
- Able to filter all items by price
- Able to list only items that are “in stock” (have at least 1 copy)
- Able to filter by individual item metadata, such as
Editionsof books orIssuesof magazines/Graphic Novels
- Perform a “Sale” of each item type
- Selling items involves the following:
- Item must implement the
ISellableinterface, which will require implementing asell()method. - Checks that at least one copy of the item is in the inventory.
- Print an error message such as: “
ERROR: 0 copies of <ITEM SHORT FORM INFO> available” when there are no copies of the item in the inventory, returnfalse.
- Print an error message such as: “
- Updates the inventory to remove a copy from the number of available items.
- Log purchases to a file: save the short-form output for the item,with the price at time of sale at the end of the line, to a file called
sales.txt.- use the short-form format with the price appended
- Print confirmation text to the console that the sale succeeded:
SOLD: <ITEM SHORT FORM INFO>
- Item must implement the
- Your code will be called by an existing test harness, which loosely follows the idea of “test driven design”. You will be provided a header file which declares all required helper functions, you will define and implement the functions and classes which will be utilized by the test code.
§5 Test Case #
All test cases are pre-defined in the main() function in test_harness.cpp, You simply need to implement all functionality defined in inventory_manager.h to complete the project. You may edit the main() function to test your code, test_harness.cpp will be restored to its original state when running tests/validate.py
§6 Grading Rubric #
- (
5%) Must have comments on your code, explaining your classes, methods, functions, and important variables. - (
1%) Able to properly load the .csv of books+metadata into your program. - (
1%) Able to properly load the .csv of magazines+metadata into your program. - (
2%) Able to properly load the .csv of cookbooks+metadata into your program. - (
2%) Able to properly load the .csv of graphic novels+metadata into your program. - (
2%) Able to properly load the .csv of children’s books+metadata into your program. - (
2%) Able to properly load the .csv of puzzle & game books+metadata into your program. - (
5%) Generates and maintains unique ID’s for all items - (
5%) Able to properly print full information for all item types to the console in the correct format. - (
10%) All items utilize polymorphism to enable interfaces withISellableandIPrintable - (
5%) Able to return a collection of items based on price. - (
5%) Able to return a collection of items based on publish date. - (
10%) Able to return a collection of items based on string matching in title and summary. - (
6%) Able to return a collection of items based on a combination of queries. - (
10%) Able to alphabetize all items, sorted by latest issue (when applicable).- HINT: capitalization may affect ascii sorting, ensure you are sorting in a case-insensitive way!
- (
7%) Can perform a “Sale()” of all items in the inventory by utilizing theISellableinterface. Selling functionality includes:- Updates the number of items in the inventory
- Adds an entry to the
sales.txtlog file. - Displays an error when there are no items left to sell
- Displays confirmation that sale succeeded.
- (
7%) Implements functionality in a cpp file corresponding with the providedinventory_manager.h(breaking the program into multiple files is also acceptable) - (
10%) Project Write Up - (
5%) UML Diagram (see below)
100% possible for a perfect implementation
+5% extra credit if you can identify the code that should be utilizing an enum in inventory_manager.h. Add a section to your write-up explaining where an enum would be useful and how it would be beneficial over the current approach.
- (-10%+) There will be a deduction for code that crashes, depending on the circumstance of the crash and mow many fixes are required to address the crash.
§7 Inputs #
You will use the provided .csv files to load data for your program. The first line of each CSV file contains a header with the data structure.
§8 Starter Code #
I have provided a test_harness.cpp and inventory_manager.h Which contain the test cases for your implementation, and the header definitions for the expected functionality.
General steps I recommend for approaching this project:
- Read the header definitions in
inventory_manager.h, complete the definition for theItemclass. - Define all classes for your program in cpp implementation files.
- Create “stub” functions to get your code to compile, a stub is a minimal function that will compile, even if it doesn’t do anything.
- After getting your program to successfully compile with stubs, start implementing functionality in small sections.
- You can freely change the
main()function intest_harness.cppto test your code as you are working, thoughtests/validate.pywill reset thetest_harness.cppbefore running.
- Once completed, run
tests/validate.pyto ensure that your program is complete.
§9 Running the project #
There are two ways to run your code, the test_harness and the tui (terminal user interface).
The test_harness is implemented in test_harness.cpp and is meant to help you verify that your code is meeting the requirements. The test harness is not exhaustive, so you must verify that you are not missing any required functionality.
The tui is implemented in tui.cpp and is an interactive interface to use your code, this is how a “real” user will interact with your code. The tui will become usable once you have completed all (or most) requirements.
§9.1 Test Harness #
You can compile the test harness using plain g++: g++ --std=c++23 -o test_harness test_harness.cpp inventory_manager.cpp (add additional .cpp files if necessary). Run the compiled binary with ./test_harness.
make is also available to compile and run the project easily, just run make run-test in the terminal to compile and run the program. if you create additional files, you will have to modify the makefile to ensure your additional .cpp files are included.
§9.2 TUI #
The tui can be compiled by using g++ --std=c++23 -o tui tui.cpp inventory_manager.cpp (add additional .cpp files if necessary). Run the compiled binary with ./tui.
make run-tui can also be used.
§10 Help #
I want you to do well, please message me on canvas, email, or join office hours if you feel lost or have any questions about the assignment or your implementation.
I am happy to answer questions or provide guidance to help you succeed.
§11 Write Up #
You will create a short write up about your experience with this project, answering a few questions:
- Did you choose to use additional Classes or Interfaces to implement your solution? Explain why you choose one over the other.
- What major problems did you encounter?
- How did you utilize polymorphism in your solution?
- Explain at a high level how you structured your program, such as how you store the list(s) of items, and how you approach filtering the data.
- Would you have preferred working with classes or structs for this project? Why?
- What was your “debug loop” for this project? How did you test your code after making changes?
- What parts of this project were notable to you?
You do not need an extensive response. just provide enough detail to clearly address the question. Aim for no more than a few sentences at most.
§12 UML Diagram #
You will also create a UML Diagram depicting your project structure. your diagram needs to fully demonstrate your class members, methods, and relationships. Your UML diagram may be submitted as part of your write-up or as a standalone file.
§13 Submission #
You will submit:
- Your project source code (on Github)
- Your UML diagram
- Your write-up pdf
Your UML Diagram may be included as part of your write up.
Be aware that your source code will be shown to the rest of the class, as we will perform a “code review” of your project implementation.