Answer to Question #229114 in C++ for Karthi

Question #229114
Define a class to represent book with the following details.
Data Members:
Book-No, Book-name, author, publisher, price, No. of copies, No.
Of copies issued.
Member Functions:
a) Assign initial values
b) Issue a book after checking availability
c) Return a book
d) Display book information
Hint- use constructors, static class members
1
Expert's answer
2021-08-26T02:27:08-0400


#include <iostream>


using namespace std;
class Book{
    private:
        int Book_No;
        string Book_name;
        string author;
        string publisher;
        double price;
        int No_of_copies;
        int No_Of_copies_issued;
    public:
        Book(){
            Book_No=1234;
            Book_name="Abcd";
            author="xyz";
            publisher="pq";
            price=1450.00;
            No_of_copies=10;
            No_Of_copies_issued=5;
        }
        void issueBook(int id){
            if (No_of_copies>=1){
                cout<<"\nBook number "<<id<<" is issued ";
                No_of_copies--;
            }
            else{
                cout<<"\nNo available book.";
            }
        }
        
        int getBook(int id){
            Book_No=id;
            return Book_No;
        }
        
        void display(){
            cout<<"\nBook number: "<<Book_No;
            cout<<"\nBook Name: "<<Book_name;
            cout<<"\nAuthor: "<<author;
            cout<<"\nPublisher: "<<publisher;
            cout<<"\nPrice: "<<price;
            cout<<"\nNumber of copies: "<<No_of_copies;
            cout<<"\nNumber of copies issued: "<<No_Of_copies_issued;
        }
};
int main()
{
    Book b;
    b.issueBook(1234);
    b.getBook(1234);
    b.display();


    return 0;
}

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