+2 votes
72 views

Please solve this assignment.

Statement is:

create a c++ class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities. using c++

by (1.2k points)   | 72 views

2 Answers

+1 vote
#include<iostream>
#include<string.h>
class Book{
    private:
        string bName, bISBN, bAuthor, bPublisher;
    public:
        Book(string n, string i, string a, string p){
            bName = n;
            bISBN = i;
            bAuthor = a;
            bPublisher = p;
        } 
        void setName(string n){
            bName = n;
        }
        string getName(){
            return bName;
        }
        void setISBN(string i){
            bISBN = i;
        }
        string getISBN(){
            return bISBN;
        }
        void setAuthor(string a){
            bAuthor = a;
        }
        string getAuthor(){
            return bAuthor;
        }
        void setPublisher(string p){
            bPublisher = p;
        }
        string getPublisher(){
            return bPublisher;
        }
        string getBookInfo(){
            string info = "Book Name:\t" + bName;
                  info += "\nISBN:\t" + bISBN;
                  info += "\nAuthor:\t" + bAuthor;
                  info += "\nPublisher:\t" + bPublisher;
            return info;
        }
};

main(){

    Book BookTest("CS201","54","Athar","Mian");

    cout<< "INFO:"<<endl;
    cout<<BookTest.getBookInfo();

}
by (1.3k points)  
Write a test application named BookTest to create an array of object for 5 elements for class Book to demonstrate the class Book's capabilities.

Note: The kinds of Book should be handled using inheritance.
Can u solve next part of this programme?
of course why not!
but if you please explain the line "The kinds of Book should be handled using inheritance", It will help to better understand the names of classes
Your program will be ready ready soon!
Create the array of 5 object(object means 5 books details)
And then explain the types of books through inheritance
That if book is comic type, friction type, language book, or science book
Create a class called Book to represent a book. A Book should include four pieces of information as instance variables:
•    A book name,
•    an ISBN number
•    an author name
•    A publisher.
A book can have following different kinds/genre
1.    Comic
2.    Fiction
3.    Language
4.    Science
Your class should have a constructor that initializes the four instance variables.
Provide a getter method and setter method (query method) for each instance variable. In addition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor.
Write a test application named BookTest to create an array of object for 5 elements for class Book to demonstrate the class Book's capabilities.

Note: The kinds of Book should be handled using inheritance.
Okay...I got it!
I'll solve it soon!
Keep visiting your question post.
Thank you so, much dear!
You are welcome!
0 votes

Try this

#include<iostream>
#include<conio.h>
using namespace std;
class Book{

    private:
        string bName, bISBN, bAuthor, bPublisher;
    public:

        Book(){

        }
        Book(string n, string i, string a, string p){
            bName = n;
            bISBN = i;
            bAuthor = a;
            bPublisher = p;
        } 

        void setName(string n){
            bName = n;
        }
        string getName(){
            return bName;
        }
        void setISBN(string i){
            bISBN = i;
        }
        string getISBN(){
            return bISBN;
        }
        void setAuthor(string a){
            bAuthor = a;
        }
        string getAuthor(){
            return bAuthor;
        }
        void setPublisher(string p){
            bPublisher = p;
        }
        string getPublisher(){
            return bPublisher;
        }

};

class Books : public Book{
    private:
     string Kind;
    public:
    void setKind(string k){
        Kind = k;
    }
    string getKind(){
        return Kind;
    }
    string getBookInfo(){
            string info = "Book Name:\t" + this->getName();
                  info += "\nISBN:\t" + this->getISBN();
                  info += "\nAuthor:\t" + this->getAuthor();
                  info += "\nPublisher:\t" + this->getPublisher();
                  info += "\nKind: \t" + Kind;
            return info;
        }
};

main(){

    Books BookTest[5];
    int NumberOfBooks = 5;
    cout<<"ENTER RECORDS: \n";
    cout<<"-------------------\n";
    for(int i=0; i<NumberOfBooks; i++){
        string n,isbn,a,p,k;
        cout<<"Book No.: " << i+1 << endl;
        cout<<"\tEnter Book Name: ";
        cin>>n;
        cout<<"\tEnter ISBN: ";
        cin>>isbn;
        cout<<"\tEnter Author: ";
        cin>>a;
        cout<<"\tEnter Publisher: ";
        cin>>p;
        cout<<"\tEnter Book Kind: ";
        cin>>k;
        BookTest[i].setName(n);
        BookTest[i].setAuthor(a);
        BookTest[i].setISBN(isbn);
        BookTest[i].setPublisher(p);
        BookTest[i].setKind(k);
    }

    system("cls");

    cout<<endl << "-------------------" <<endl;
    cout<<"BOOK DETAILS";
    cout<<endl << "-------------------" <<endl;

    for(int k=0; k<NumberOfBooks; k++){
        cout<<"Book No.: " << k+1 <<endl;
        cout<<"\tBook Name: "<< BookTest[k].getName() << endl;
        cout<<"\tBook ISBN: "<< BookTest[k].getISBN() << endl;
        cout<<"\tBook Author: "<< BookTest[k].getAuthor() << endl;
        cout<<"\tBook Publisher: "<< BookTest[k].getPublisher() << endl;
        cout<<"\tBook Kind: "<< BookTest[k].getKind() << endl;
    }

}

Here is a screenshot

image.png

by (1.3k points)  
if you dont want to inherit class, simply remove the second class and put setKind and getKind methods into the 1st one.

Related questions

+2 votes
3 answers
+1 vote
1 answer
asked Jun 27 by fatyma Nauman (485 points) | 24 views
+1 vote
2 answers
+3 votes
0 answers
+2 votes
1 answer
+2 votes
1 answer
asked Jun 11 by noor (1.1k points) | 18 views
+2 votes
1 answer
+3 votes
1 answer




Welcome to Meansflow - Where Developers and Students Learn, Share, & Build Careers, where you can ask questions and receive answers from other members of the community.
113 questions
85 answers
38 comments
103 users