#include <iostream>
#include <cstring>

class Book {
private:
    char author[50];
    char title[100];
    float price;
    char publisher[50];
    int stockPosition;

public:

    Book() : price(0.0), stockPosition(0) {
        author[0] = '\0';
        title[0] = '\0';
        publisher[0] = '\0';
    }
    Book(const char* _author, const char* _title, float _price, const char* _publisher, int _stockPosition)
        : price(_price), stockPosition(_stockPosition) {
        strncpy(author, _author, sizeof(author) - 1);
        author[sizeof(author) - 1] = '\0';
        strncpy(title, _title, sizeof(title) - 1);
        title[sizeof(title) - 1] = '\0';
        strncpy(publisher, _publisher, sizeof(publisher) - 1);
        publisher[sizeof(publisher) - 1] = '\0';
    }

    void displayBookDetails() {
        std::cout << "Author: " << author << std::endl;
        std::cout << "Title: " << title << std::endl;
        std::cout << "Price: $" << price << std::endl;
        std::cout << "Publisher: " << publisher << std::endl;
        std::cout << "Stock Position: " << stockPosition << std::endl;
    }
    void processBookRequest(int requestedCopies) {
        if (stockPosition >= requestedCopies) {
            float totalCost = price * requestedCopies;
            std::cout << "Requested copies are available." << std::endl;
            std::cout << "Total cost: $" << totalCost << std::endl;
            stockPosition -= requestedCopies; // Update stock
        } else {
            std::cout << "Required copies not in stock." << std::endl;
        }
    }
};

int main() {
    Book book1("John Doe", "Programming Basics", 29.99, "Tech Books Inc.", 50);

    
    book1.displayBookDetails();
    
    int requestedCopies;
    std::cout << "Enter the number of copies required: ";
    std::cin >> requestedCopies;

    book1.processBookRequest(requestedCopies);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: