Repository navigation
Bookstore Wiki
- Intro
- Files
- How to compile
- All make rules
- How to fix some bugs
- Book Class
- Catalog Class
- Menu Class
- Txt files
- Unused functions
This is a program made in C++. It was made for fun. To use it, you need to use either a Linux based system or Windows if you have GNU Make (I don't own it).
Except the License, img folder, the .gitattributes, .gitignore, the .vscode and README.md, you have the following:
- src directory containing: main.cpp, menu.h, menu.cpp, book.h, book.cpp, catalog.h, catalog.cpp;
- Makefile;
To compile, you just need to be in the same directory level as the Makefile file and to type make. Sometimes, if you edit a .cpp file, you may need to type make clean.
As mentioned in the README.md:
You need to type in terminal
make rule_you_wantin the same level of directory as the Makefile file. All make commands:
| Command | Creates the executable | Cleans the objects | Cleans the log | Runs the program | Debug | Simple valgrind | Leak check | All valgrind info |
|---|---|---|---|---|---|---|---|---|
| make (all) | yes | x | x | x | x | x | x | x |
| make clean | x | yes | x | x | x | x | x | x |
| make valgrind_clean | x | x | yes | x | x | x | x | x |
| make run | yes | x | x | yes | x | x | x | x |
| make debug | yes | x | x | yes | x | x | x | x |
| make valgrind | yes | x | x | yes | x | yes | x | x |
| make valgrind_leakcheck | yes | x | x | yes | x | yes | yes | x |
| make valgrind_extreme | yes | x | x | yes | x | yes | yes | yes |
If you have one of the errors:
Error: 'books/catalog.txt' is missing, the program stopped!
This means that you somehow managed to not have the file catalog.txt inside the books directory, or somehow the path is not good.
'books/prices.txt' is missing, the program stopped!
This means that you somehow managed to not have the file prices.txt inside the books directory, or somehow the path is not good.
A "Book" object contains the following informations:
| Member | Type | Default Value | Description | Is it important |
|---|---|---|---|---|
| year | int | 1970 | Used for book information | No |
| count | int | 1 | Number of copies of the book | Yes |
| id | int | 0 | Id of the book | Yes |
| name | std::string | "Book Class" | Name of the book | Yes |
| author | std::string | "Lucky8boy" | Author of the book | No |
| description | std::string | "Some cool description" | Description of the book | No |
This class contains 4 more constructors (more details if needed in another Wiki page), 3 setters, 3 getters and 4 more special functions.
| Functions | Type | Description | Is it used in the repo's menu? |
|---|---|---|---|
| displayBook | void | Shows in terminal all info about the book | Yes |
| addToCatalog | void | Manually adds a .txt file about the book, but without updating the catalog I made | No |
| createFile | void | Creates a .txt file about the book containing all of its info | Yes |
| destroyFile | void | Deletes the .txt files about the book | Yes |
A "Catalog" object contains the following members:
| Member | Type | Default Value | Description | Is it important |
|---|---|---|---|---|
| mapData | std::unordered_map<std::string, int> | None | It contains the id, name and number of copies from each book | Yes |
| prices | std::unordered_map<int, double> | None | It contains the id and price of each book | Yes |
| data | std::list | None | Almost as mapData, but is a list and has one more thing: the id | Yes |
| numOfBooks | int | None | It remembers the numbers of books the catalog has | Yes |
It contains another constructor which gives to it's members all data needed. To update the "Catalog", data needs to work. The Trio is a struct type which contains the following:
Definition:
typedef struct Trio {
int id, count;
std::string name;
} Trio;
// used for 'std::list<Trio> data' in 'Catalog' class id, count and name have the same informations as the 3 / 6 members of a "Book" object. Used in the linked list structure data to update the catalog whenever it is needed.
| Functions | Type | Arguments | Description | Priority level |
|---|---|---|---|---|
| showCatalog | void | None | Prints all the content of the catalog | Low |
| updateCatalog | void | None | Updates the catalog.txt file | Crucial |
| addBook | void | Book book | Add a book in the data, but it updates the catalog | Crucial |
| searchBook | bool | int id | Searches a book by it's id. Returns 1 if found, 0 if not. | High importance |
| searchBook | void | std::string name | Searches a book by it's name. Returns it's id, -1 if it doesn't exists | Important |
| removeBook | void | Book book | Removes a book from data, but it updates the catalog | Crucial |
| buyBook | void | int id | If id exists, it "buys" a book. If the number of copies was 1, the book is removed from the catalog and it is updated | Important |
| buyBook | void | std::string name | Same as the before, except it uses name instead of id | Important |
A "Menu" contains the following members:
| Member | Type | Default Value | Description | Is it important |
|---|---|---|---|---|
| sWelcome | const std::string | "Welcome to my bookstore!\n" | Just a welcome message | No |
| options | const int | 5 | Number of strings in sOptions | No |
| sOptions | const std::string[] | {"1. Add book\n", "2. Remove book\n", "3. Check if book exists\n", "4. Buy book\n", "5. Exit\n"} | Strings used to display the menu | Yes |
There are only two important .txt files: catalog.txt and prices.txt.
"catalog.txt" contains on the first line the number of books that exists.
Warning! If there are no books, the file should only contain the following thing:
0
If it doesn't exists, the program breaks!
The other lines look like this:
| Id | Number of copies | Book's name |
|---|---|---|
| 1 | 23 | Some book name |
| 2 | 42 | Another book name |
| 3 | 2 | A cool name |
| 4 | 1 | And so |
| 5 | 23 | On |
"prices.txt" can be empty and (if not empty) can look like this:
| Id | Price |
|---|---|
| 1 | 23.99 |
| 2 | 14.99 |
| 3 | 0 |
| 4 | 49.99 |
If the "catalog.txt" contains books, each book will have it's own .txt file with it's name. If a book is removed, the .txt file will be removed.
| Functions | Type | Arguments | Description | Possibile priority level |
|---|---|---|---|---|
| Book | Constructor | int count, std::string name | Creates a "Book" object which contains only the name and the number of copies | Very low |
| Book | Constructor | int year, int count, std::string name, std::string author | Creates a "Book" object which containts all the possible informations except the id | Normal |
| addToCatalog | void | None | Adds just a .txt file for the book | Very high |
| setCount | void | None | Sets the number of copies | High |
| setName | void | None | Sets the name | High |