C++ Bookshop Management System Console Project with source code

We’ll create a simple C++ Bookshop Management System Console Project with source code in this article. This console-based application allows users to manage a bookshop’s inventory, add new books, update book details, and display the available books. The project will include adding books, modifying book information, deleting books, and displaying the book inventory.

Overview of the Bookshop Management System Project in C++


Creating a full-fledged Bookshop Management System project involves multiple files and more detailed implementation, including functionalities like modification, deletion, and possibly file handling for data persistence. Below is an extended version of the C++ code for a simplified Bookshop Management System. This example includes a class for handling file operations and a menu for user interaction. The Bookshop Management System project is designed to streamline the process of managing a bookshop’s inventory. Key features include:

Add Book: Allow the user to add a new book to the inventory, providing details like book ID, title, author, genre, and quantity.

Modify Book: Enable the user to modify existing book details, including title, author, genre, and quantity.

Delete Book: Provide the functionality to remove a book from the inventory based on the book ID.

Display Books: Display a list of all available books with their respective details.

Steps to Set Up the Bookshop Management Sytem Project on Your Machine

Download the Project Files:

Download the project files from the provided link to download the zip file for the source code.

GitHub Repository:

Click on the button below to clone the GitHub Repository to run that project on your machine.

Extract and Compile:

Extract the downloaded files to your preferred location. Open a C++ compiler (e.g., IntelliJ Idea, Visual Studio Code, DevC++, or any other of your choice). Open the main C++ file (source.cpp) and compile the Bokk Shot Management System project.

Run the Application:

Run the compiled executable file to launch the console-based Bookshop Management System.

Interact with the System:

Use the menu-driven interface to add, modify, delete, and display books in the bookshop inventory.

Code Explanation

The C++ code for the Bookshop Management System includes a Book representing a book, and a Bookshop class managing the book inventory. Functions are provided for adding books, modifying book details, deleting books, and displaying the book inventory.

The main function acts as the entry point, presenting a menu for users to choose different operations.

C++ Bookshop Management System Console Project with source code

#include<iostream>
#include<iomanip>
#include<vector>
#include<fstream>
#include<string>

using namespace std;

class Book {
public:
    int bookId;
    string title;
    string author;
    string genre;
    int quantity;

    void displayBookDetails() const {
        cout << "Book ID: " << bookId << "\nTitle: " << title << "\nAuthor: " << author << "\nGenre: " << genre << "\nQuantity: " << quantity << endl;
    }
};

class BookshopManagementSystem {
private:
    vector<Book> books;
    const string filename = "book_inventory.dat";

public:
    void addBook() {
        Book newBook;
        cout << "Enter Book ID: ";
        cin >> newBook.bookId;
        cin.ignore();  // Clear newline from buffer
        cout << "Enter Title: ";
        getline(cin, newBook.title);
        cout << "Enter Author: ";
        getline(cin, newBook.author);
        cout << "Enter Genre: ";
        getline(cin, newBook.genre);
        cout << "Enter Quantity: ";
        cin >> newBook.quantity;

        books.push_back(newBook);
        saveDataToFile();
        cout << "Book added successfully!" << endl;
    }

    void displayAllBooks() const {
        if (books.empty()) {
            cout << "No books available in the inventory." << endl;
            return;
        }

        cout << "Book Inventory:\n";
        for (const Book& book : books) {
            book.displayBookDetails();
            cout << "------------------------\n";
        }
    }

    void modifyBook(int bookId) {
        for (Book& book : books) {
            if (book.bookId == bookId) {
                cout << "Modify Book ID " << bookId << ":\n";
                cout << "Enter New Title: ";
                getline(cin, book.title);
                cout << "Enter New Author: ";
                getline(cin, book.author);
                cout << "Enter New Genre: ";
                getline(cin, book.genre);
                cout << "Enter New Quantity: ";
                cin >> book.quantity;

                saveDataToFile();
                cout << "Book modified successfully!" << endl;
                return;
            }
        }

        cout << "Book with ID " << bookId << " not found." << endl;
    }

    void loadDataFromFile() {
        ifstream inFile(filename, ios::binary);
        if (!inFile) {
            cout << "No existing data file found. Starting with an empty inventory." << endl;
            return;
        }

        while (!inFile.eof()) {
            Book loadedBook;
            inFile.read(reinterpret_cast<char*>(&loadedBook), sizeof(Book));
            if (inFile.eof()) {
                break;
            }
            books.push_back(loadedBook);
        }

        inFile.close();
    }

    void saveDataToFile() const {
        ofstream outFile(filename, ios::binary);
        for (const Book& book : books) {
            outFile.write(reinterpret_cast<const char*>(&book), sizeof(Book));
        }
        outFile.close();
    }

    ~BookshopManagementSystem() {
        saveDataToFile();
    }

    // Add more functionalities like delete, search, etc., based on your requirements
};

int main() {
    BookshopManagementSystem bookshop;
    bookshop.loadDataFromFile();

    char choice;
    do {
        cout << "Menu:\n1. Add Book\n2. Display All Books\n3. Modify Book\n4. Exit\nEnter your choice: ";
        cin >> choice;

        switch (choice) {
        case '1':
            bookshop.addBook();
            break;
        case '2':
            bookshop.displayAllBooks();
            break;
        case '3': {
            int bookId;
            cout << "Enter Book ID to modify: ";
            cin >> bookId;
            cin.ignore();  // Clear newline from buffer
            bookshop.modifyBook(bookId);
            break;
        }
        case '4':
            cout << "Exiting the Bookshop Management System. Thank you!\n";
            break;
        default:
            cout << "Invalid choice. Please try again.\n";
        }
    } while (choice != '4');

    return 0;
}

What is the Bookshop Management System project?

The Bookshop Management System is a console-based application developed in C++ for managing book inventories in a bookshop. It provides functionalities like adding books, displaying all books, and modifying book details.

How do I download and run the project?

Download the project files from the provided GitHub repository.
Compile the source code using a C++ compiler such as Code::Blocks or DevC++.
Run the compiled executable to interact with the Bookshop Management System.

What are the key features of the Bookshop Management System?

Comprehensive book inventory control.
User-friendly console interface.
Dynamic data handling for adding, modifying, and deleting books.
Optimized code structure following best practices in C++ programming.