Answer to Question #217142 in C++ for Srikanth Kodamasim

Question #217142
A book shop maintains the inventory of books that are being sold at their shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise "Required copies not in stock" is displayed. Design a

system using a class called books with suitable member functions and constructors. Use new operator in constructors to allocate memory space required.
1
Expert's answer
2021-07-15T01:53:22-0400
#include <iostream>

using namespace std;

class Book
{
private:
    string author, title, publisher;
    int price, stockPos;
public:
    Book(string au, string ti, string pub, int pri, int stock) {
        this -> author=au;
        this -> title=ti;
        this -> publisher=pub;
        this -> price=pri;
        this -> stockPos=stock;
    }
    void enter() {
        cout << "Input a book author: ";
        cin >> author;
        cout << "Input a book title: ";
        cin >> title;
        cout << "Input a book publisher: ";
        cin >> publisher;
        cout << "Input a book price: ";
        cin >> price;
        cout << "Input a book stock position: ";
        cin >> stockPos;
    }
    void display() {
        cout << "Author: " << author << '\n';
        cout << "Title: " << title << '\n';
        cout << "Publisher: " << publisher << '\n';
        cout << "Price: " << price << '\n';
        cout << "Stock position: " << stockPos << '\n';
    }

};

int main()
{
    Book *harry = new Book("J.K. Rowling", "Harry Potter book 1", "Bloomsbury", 16, 1);
    harry->display();

    return 0;
}

Example:
Author: J.K. Rowling
Title: Harry Potter book 1
Publisher: Bloomsbury
Price: 16
Stock position: 1

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS