§1 Project 1 #
The owner of a small bookstore is looking to modernize their store’s inventory system with new software. This software will track and store inventory information about all the books in the store.
§2 Info #
For this project, you are going to decide how to structure your program, including data representation, function parameters, and return types. You have the flexibility to implement it in any way that meets the rubric requirements. Your grade will be based solely on how well you fulfill those criteria.
I encourage you to review the posts and feedback from last week’s discussion board. This project will serve as a culmination of many of the concepts you have learned so far. Unlike small assignments, larger projects present unique challenges and pitfalls in software development that are not immediately apparent.
The decisions you make throughout this project will significantly impact the structure and functionality of your final program. It is common to realize, after writing some code, that initial choices need to be revised or restructured to improve the overall design. This process of iteration and refinement is a key part of software development.
Future projects will build on the code you develop now and will introduce more complex requirements. It will be helpful to write your code with scalability and adaptability in mind. Consider how your codebase can be reused, extended, or refactored as new features and requirements are added. Here are some important considerations:
- Function Naming: Are your function names descriptive enough to convey their purpose? Clear and meaningful names make your code easier to understand and maintain.
- Comment Quality: Are your comments informative and helpful for your future self or others who might read your code? Good comments explain why certain decisions were made, not just what the code does.
- Modularity: Are your functions broken down into smaller, single-purpose modules that can be reused in different contexts? Avoid duplicating code by creating versatile functions that can be called in multiple scenarios.
- Scalability and Flexibility: Have you thought about how changes to one part of your code might impact other areas? Writing code that can be easily adapted to new requirements will save you time and effort in future projects.
- Data Handling: How do you move data around your program? Will you use global variables, function parameters, structs, etc.?
By keeping these points in mind, you should develop a more robust and maintainable codebase that can handle the growing complexity of future assignments.
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.
§3 Guidelines #
You may use a single file or several files for your source code.
You may utilize any combination of containers to represent the list of books in your program, this could be arrays, structs, vectors, lists, etc.
Here is a list of features for your Inventory Management Software:
- Book Information:
- Program receives an argument for which file to load data from.
- This functionality is provided in the starter code.
- Load each book’s metadata from the provided CSV file. (Look at the starter code for some guidance on loading from .csv files.)
- Metadata:
title,author,ID,price,year published,pagecount,genre,summary. - The
IDof a book will correspond with its position in the .csv file.- e.g., the first book should have
ID=0, the second book hasID=1, etc.
- e.g., the first book should have
- Metadata:
- Ability to update the number of books in the store inventory.
- Output:
Consider whether you should use
operator<<overloading or functions to implement the output functionality. Both approaches are valid and come with trade-offs.
Ability to print a single book’s full information:
- Print all information on one line, in the form
KEY: VALUE |
(The key/value pairs can be printed in any order, as long as all information is printed.)
Example:
Title: War and Peace | Author: Leo Tolstoy | ID: 9 | Price: 18.99 | Year Published: 1869 | Page Count: 1225 | Genre: Historical Fiction | Summary: A sweeping narrative of Russian society during the Napoleonic era. | Copies: 2- Print all information on one line, in the form
Ability to print a single book’s title, author, ID in the shorthand format
ID; TITLE; AUTHOR; INVENTORY_COUNT(semicolon-separated):9; War and Peace; Leo Tolstoy; 2When printing, the output must match the current state of the inventory.
- Search and Sorting Features:
Take time to carefully consider how your functions should return data, as there are multiple approaches to choose from. For example, you could use
voidfunctions that simply print the output, functions that return new lists containing subsets of books, or functions that return references to books within an existing list.
Each choice has trade-offs in terms of modularity and complexity. A key objective of this project is to help you gain experience with integrating code into a larger project, where seemingly minor decisions about your design can significantly impact the overall structure of your program.
Ability to return a list of books sorted in alphabetical order by title.
std::sortmay be helpful here:
Ability to take input parameters and return a list of books that fit certain criteria.
- e.g., return all books that match a given genre, like “Fantasy” or “Drama”.
- An example function prototype (you will likely use a different name, parameters, and return type):
Books[] filterGenre(Books[] &bookArray, string genre);
- An example function prototype (you will likely use a different name, parameters, and return type):
- Ability to return all books written by a given author, like “F. Scott Fitzgerald”.
- Ability to return all books that are above or below a specified price.
- Ability to return all books that are above or below a specified page count.
- e.g., return all books that match a given genre, like “Fantasy” or “Drama”.
Provide basic search functionality; it should return a list of all books whose title contains a queried word.
- e.g., the string “and” should return
3books from the example inputbooks.csv. std::findmay be helpful here:
- e.g., the string “and” should return
- Purchasing:
Facilitate the sale of a book to a customer:
- Check that at least one copy of the book is in the inventory.
- Print an error message such as: “
ERROR: 0 copies of book 'BOOKNAME' available” when there are no copies of the book in the inventory.
- Print an error message such as: “
- Update the inventory to remove a copy from the number of available books.
- Log book purchases to a file: save the book ID, title, author, and price at time of sale to a file called
sales.txt.- Use the format:
ID; TITLE; AUTHOR; $PRICE; INVENTORY_COUNT(don’t forget the currency sign). INVENTORY_COUNTshould reflect the count AFTER the book is sold.
- Use the format:
- Print confirmation text to the console that the sale succeeded:
BOOKNAME sold.
Contents of the file “sales.txt”:
0; The Great Gatsby; F. Scott Fitzgerald; $10.5; 1 11; The Lord of the Rings: The Two Towers; J.R.R. Tolkien; $13.99; 6 0; The Great Gatsby; F. Scott Fitzgerald; $10.5; 0- Check that at least one copy of the book is in the inventory.
- Limitations:
- You may not use C++ classes in your solution; if you use structs, you may not use member functions either, operator overloading is fine. (We will use classes later on; I want to be able to compare and contrast Imperative vs. Object-Oriented Programming approaches.)
§4 Test Case #
All test cases are already outlined in the example starter.cpp file. You just need to add functionality for each section.
Most of your logic should be implemented outside of main(); your main() should primarily consist of calls to other functions, and perhaps some basic loops to iterate over your book list.
§5 Grading Rubric #
All tests will be verified with multiple different input files.
- (
5%) Project write-up, details at the bottom of this README - (
2.5%) Must have comments on your code, explaining your functions, data structures, and any variables that are not temporary. - (
10%) Able to load .csv of books into your program, including CSV files from arguments, e.g.,./project1 books-alt.csv - (
5%) Able to properly print full information for a single book to the console in the expected format.Title: War and Peace | Author: Leo Tolstoy | ID: 9 | Price: 18.99 | Year Published: 1869 | Page Count: 1225 | Genre: Historical Fiction | Summary: A sweeping narrative of Russian society during the Napoleonic era. | Copies: 2 - (
5%) Able to print title, author, and ID for a single book to the console in the expected format.term 9; War and Peace; Leo Tolstoy; 2 - (
10%) Able to print the full list of books in alphabetical order to the console, in both short and full formats. - (
5%) Able to set the number of copies of a book in the inventory. - (
5%) Able to print a list of books that cost less than a specified value. - (
5%) Able to print a list of books that belong to a specified genre. - (
5%) Able to print a list of books that are written by a specified author. - (
5%) Able to print a list of books that are longer than a specified page count. - (
5%) Able to combine filters: print a list of books that are written by a specific author AND are longer than a specified page count. - (
5%) Able to perform a search for books with specific text in the title. - Implements book “selling” functionality which:
- (
5%) Updates the number of copies of the book in the inventory. - (
5%) Adds a properly formatted entry to thesales.txtlog file (ID; TITLE; AUTHOR; $PRICE; INVENTORY_COUNT). - (
5%) Properly handles the error case when there are no copies of a book to sell. - (
5%) Displays confirmation that sale succeeded.
- (
- (
5%) Able to perform a “sale” of a book with a specific ID. - (
5%) Able to perform a “sale” of a book by title. - (
2.5%) Properly implements amain()function with all Test Cases from the starting code (there will be no deduction for unimplemented sections in yourmain()function).
- DO NOT USE CLASSES. More info in the “penalties” section below.
Your grade is based on adherence to the rubric.
Use tests/validate.py to check your work; it will let you know if any sections are incomplete.
NOTE: While I tried to make the test as forgiving as possible, you may have creative edge cases that I did not foresee. If the test is failing and you believe your implementation is correct, feel free to message me.
The max score for this assignment is 105%, allowing some leeway for an incomplete assignment to still score well, since this is a fairly complicated assignment.
Penalties:
- (
-30%) DO NOT use classes or member functions. Structs are allowed, and operator overloading is also allowed. (We will compare and contrast object-oriented vs. imperative programming paradigms) - Code that fails to compile cannot be graded and will receive a
0. Ensure that your submitted code can at least compile and run with the providedbooks.csv.
§6 Extra Credit #
You can earn an additional 10% extra credit by making your program capable of ingesting “messy” data. With real datasets, it’s common to have issues or inconsistencies with the input data, sometimes you need to be able to handle edge cases.
In the file books-alt-hard.csv, an additional book with inconsistent formatting is added at the top (ID=0). The price of this book is formatted as an integer instead of a float, and the description is quote-escaped due to extra commas in the description.
If you can improve your import function to handle these edge cases, you can earn the extra credit. The extra credit is all-or-nothing. I suggest completing, committing, and syncing your regular submission, before attempting this more complex challenge. Thanks to git, you can easily change or revert your changes later, as it keeps a history of every change you commit.
To get the extra credit, be sure to let me know that your program is capable of reading books-alt-hard.csv, and also add an extra section to your write-up explaining how you went about solving this challenge.
§7 Inputs #
I have provided some input files for you to use in this lab; the examples on this document have all used books.csv as an input. You also have access to books-alt.csv as a secondary example you can test with. I will use several files like these to test that your program is functioning correctly. The books-alt-hard.csv will be discussed in the extra-credit section.
§8 Starter Code #
I have provided a main.cpp file with some starter code. This file has an example function to load data from the provided CSV files; you will need to modify the function to load the data into your chosen data structure.
The main() function is also partially started, with the sections of the test already defined for you; you just need to add your logic to each section of the main() function.
§9 Output #
The provided main.cpp as-is has the following “blank” output:
=== 1. Load the list of books from a file. ===
=== 2. Print full information of book with ID=0. ===
=== 3. Print compact form (ID, title, author, count) of book with ID=0. ===
=== 4. Update inventory count of book with ID=1 to `2`. ===
=== 5. Print the full information of book with ID=1 ===
=== 6. Print the full alphabetized list of books in compact form ===
=== 7. Print compact info of all books that cost less than $10.51 ===
=== 8. Print compact info of all books that belong to the 'Fantasy' genre ===
=== 9. Print compact info of all books written by 'J.R.R. Tolkien' AND longer than 325 pages ===
=== 10. Print compact info of all books whose titles contain the text 'and' ===
=== 11. Perform a 'sale' of the book with ID=0 ===
=== 12. Perform a 'sale' of the book: 'The Lord of the Rings: The Two Towers' ===
=== 13. Attempt two more sales of the book with ID=0, second 'sale' should fail. ===
=== 14. Print the full info of all books in alphabetical order ===
The completed project should have the following output, order does not matter in non-alphabetized sections (some completed sections will have no output):
=== 1. Load the list of books from a file. ===
=== 2. Print full information of book with ID=0. ===
Title: The Great Gatsby | Author: F. Scott Fitzgerald | ID: 0 | Price: 10.5 | Year Published: 1925 | Page Count: 180 | Genre: Fiction | Summary: A story about the mysterious Jay Gatsby and the American Dream. | Copies: 2
=== 3. Print compact form (ID, title, author, count) of book with ID=0. ===
0; The Great Gatsby; F. Scott Fitzgerald; 2
=== 4. Update inventory count of book with ID=1 to `2`. ===
=== 5. Print the full information of book with ID=1 ===
Title: To Kill a Mockingbird | Author: Harper Lee | ID: 1 | Price: 10.99 | Year Published: 1960 | Page Count: 281 | Genre: Fiction | Summary: A novel about racial injustice in the Deep South. | Copies: 2
=== 6. Print the full alphabetized list of books in compact form ===
3; 1984; George Orwell; 5
5; Brave New World; Aldous Huxley; 10
7; Crime and Punishment; Fyodor Dostoevsky; 11
4; Moby Dick; Herman Melville; 4
2; Pride and Prejudice; Jane Austen; 3
6; The Catcher in the Rye; J.D. Salinger; 3
0; The Great Gatsby; F. Scott Fitzgerald; 2
8; The Hobbit; J.R.R. Tolkien; 8
10; The Lord of the Rings: The Fellowship of the Ring; J.R.R. Tolkien; 3
12; The Lord of the Rings: The Return of the King; J.R.R. Tolkien; 5
11; The Lord of the Rings: The Two Towers; J.R.R. Tolkien; 7
1; To Kill a Mockingbird; Harper Lee; 2
9; War and Peace; Leo Tolstoy; 2
=== 7. Print compact info of all books that cost less than $10.51 ===
0; The Great Gatsby; F. Scott Fitzgerald; 2
2; Pride and Prejudice; Jane Austen; 3
3; 1984; George Orwell; 5
=== 8. Print compact info of all books that belong to the 'Fantasy' genre ===
8; The Hobbit; J.R.R. Tolkien; 8
10; The Lord of the Rings: The Fellowship of the Ring; J.R.R. Tolkien; 3
11; The Lord of the Rings: The Two Towers; J.R.R. Tolkien; 7
12; The Lord of the Rings: The Return of the King; J.R.R. Tolkien; 5
=== 9. Print compact info of all books written by 'J.R.R. Tolkien' AND longer than 325 pages ===
10; The Lord of the Rings: The Fellowship of the Ring; J.R.R. Tolkien; 3
11; The Lord of the Rings: The Two Towers; J.R.R. Tolkien; 7
12; The Lord of the Rings: The Return of the King; J.R.R. Tolkien; 5
=== 10. Print compact info of all books whose titles contain the text 'and' ===
2; Pride and Prejudice; Jane Austen; 3
7; Crime and Punishment; Fyodor Dostoevsky; 11
9; War and Peace; Leo Tolstoy; 2
=== 11. Perform a 'sale' of the book with ID=0 ===
The Great Gatsby sold.
=== 12. Perform a 'sale' of the book: 'The Lord of the Rings: The Two Towers' ===
The Lord of the Rings: The Two Towers sold.
=== 13. Attempt two more sales of the book with ID=0, second 'sale' should fail. ===
The Great Gatsby sold.
ERROR: 0 copies of book 'The Great Gatsby' available
=== 14. Print the full info of all books in alphabetical order ===
Title: 1984 | Author: George Orwell | ID: 3 | Price: 9.99 | Year Published: 1949 | Page Count: 328 | Genre: Dystopian | Summary: A dystopian story about a totalitarian regime and surveillance. | Copies: 5
Title: Brave New World | Author: Aldous Huxley | ID: 5 | Price: 11.99 | Year Published: 1932 | Page Count: 311 | Genre: Dystopian | Summary: A futuristic society controlled by technology and conditioning. | Copies: 10
Title: Crime and Punishment | Author: Fyodor Dostoevsky | ID: 7 | Price: 14.99 | Year Published: 1866 | Page Count: 671 | Genre: Philosophical Fiction | Summary: A psychological exploration of morality and guilt. | Copies: 11
Title: Moby Dick | Author: Herman Melville | ID: 4 | Price: 12.5 | Year Published: 1851 | Page Count: 635 | Genre: Adventure | Summary: The tale of Captain Ahab's obsessive quest to kill the white whale Moby Dick. | Copies: 4
Title: Pride and Prejudice | Author: Jane Austen | ID: 2 | Price: 8.99 | Year Published: 1813 | Page Count: 279 | Genre: Romance | Summary: A classic romance novel exploring themes of class and marriage. | Copies: 3
Title: The Catcher in the Rye | Author: J.D. Salinger | ID: 6 | Price: 10.99 | Year Published: 1951 | Page Count: 214 | Genre: Fiction | Summary: A story about teenage rebellion and alienation. | Copies: 3
Title: The Great Gatsby | Author: F. Scott Fitzgerald | ID: 0 | Price: 10.5 | Year Published: 1925 | Page Count: 180 | Genre: Fiction | Summary: A story about the mysterious Jay Gatsby and the American Dream. | Copies: 0
Title: The Hobbit | Author: J.R.R. Tolkien | ID: 8 | Price: 12.99 | Year Published: 1937 | Page Count: 310 | Genre: Fantasy | Summary: The adventures of Bilbo Baggins in Middle-earth. | Copies: 8
Title: The Lord of the Rings: The Fellowship of the Ring | Author: J.R.R. Tolkien | ID: 10 | Price: 13.99 | Year Published: 1954 | Page Count: 423 | Genre: Fantasy | Summary: The first part of the epic trilogy where Frodo begins his journey to destroy the One Ring. | Copies: 3
Title: The Lord of the Rings: The Return of the King | Author: J.R.R. Tolkien | ID: 12 | Price: 13.99 | Year Published: 1955 | Page Count: 416 | Genre: Fantasy | Summary: The final part of the trilogy where the fate of Middle-earth is decided. | Copies: 5
Title: The Lord of the Rings: The Two Towers | Author: J.R.R. Tolkien | ID: 11 | Price: 13.99 | Year Published: 1954 | Page Count: 352 | Genre: Fantasy | Summary: The second part of the trilogy following the separate journeys of the Fellowship members. | Copies: 6
Title: To Kill a Mockingbird | Author: Harper Lee | ID: 1 | Price: 10.99 | Year Published: 1960 | Page Count: 281 | Genre: Fiction | Summary: A novel about racial injustice in the Deep South. | Copies: 2
Title: War and Peace | Author: Leo Tolstoy | ID: 9 | Price: 18.99 | Year Published: 1869 | Page Count: 1225 | Genre: Historical Fiction | Summary: A sweeping narrative of Russian society during the Napoleonic era. | Copies: 2
§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 Submission #
Commit and sync your code just like any other assignment in this class.
Also submit a short write-up on Canvas, details are in the next section.
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.
The Due Date and the Close Date for the project are strict. This project has more time than other assignments to complete, but is also expected to take more time than other assignments.
Late work will not be accepted. Due to how long these projects take to grade, I am unable to accept resubmissions after grading in order to maintain fairness for all students.
Submit early to avoid the risk of receiving a zero due to mistakes like uploading the wrong file. I will let you know if your project submission has major issues so you have time to fix it, but you will not get an opportunity to fix it after the due date.
§12 Deliverables #
- Your source code via Github.
- A Canvas-submitted write-up that contains the following:
- A brief explanation of how you chose to implement your program and why you chose your approach.
- Instructions on how to compile and run your program.
- A list of any extra sources you used to help you with your program (asking ChatGPT or other LLMs for help is fine; tell me about that here).
- What parts of this project you struggled with or otherwise felt notable to you.