Question

Problem 1: bookType Design a bookType class that defines the book as an ADT. Some of...

Problem 1: bookType

Design a bookType class that defines the book as an ADT. Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. You only need to design the interface (.h file) and not the implementation (.cpp file)

  • Each object of the class bookType can hold the following information about a book: title, up to four authors, publisher, ISBN, price, and number of copies in stock.
  • To keep track of the number of authors, add another member variable.
  • Include the member functions to perform the various operations on objects of type bookType. For example, the usual operations that can be performed on the title are to show the title, set the title, and check whether a title is the same as the actual title of the book.
  • Similarly, the typical operations that can be performed on the number of copies in stock are to show the number of copies in stock, set the number of copies in stock, update the number of copies in stock, and return the number of copies in stock.
  • Add similar operations for the publisher, ISBN, book price, and authors.
  • Add the appropriate constructors.

Homework Answers

Answer #1

bookType.h :

#include <iostream>
#include <vector>
#include<string>
#include <algorithm>
using namespace std;
class bookType
{
    private:
    
    string title;
    int nauthor;
    vector <string> author;
    string publisher;
    string ISBN;
    int copies;
    int price;
    string YearOfPub;
    
    public:
    
    bookType()
    {
        vector <string> temp(0,"");
        title = "";
        nauthor = 0;
        author = temp;
        publisher = "";
        ISBN = "";
        copies = 0;
        price=0;
        YearOfPub = "";
    }
    
    bookType(string t,vector <string> a,string p,string i, int c,int pr,string y)
    {
        title = t;
        author = a;
        nauthor = author.size();
        publisher = p;
        ISBN = i;
        copies = c;
        price=pr;
        YearOfPub = y;
    }
    
    void setTitle(string s)
    {
       title = s; 
    }
    bool isTitle(string s)
    {
        return (s==title);
    }
    string getTitle()
    {
        return title;
    }
    
    void setCopies(int n)
    {
       copies = n; 
    }
    int getCopies()
    {
        return copies;
    }
    void updateCopies(int n)
    {
        setCopies(n);
    }
    
    void setPublisher(string s)
    {
        publisher = s;
    }
    string getPublisher()
    {
        return publisher;
    }
    bool isPublisher(string s)
    {
        return (publisher==s);
    }
    
    void setISBN(string s)
    {
        ISBN = s;
    }
    string getISBN()
    {
        return ISBN;
    }
    bool checkISBN(string s)
    {
        return (ISBN==s);
    }
    
    void setPrice(int n)
    {
        price = n;
    }
    int getPrice()
    {
        return price;
    }
    void updatePrice(int n)
    {
        setPrice(n);
    }
    
    void addAuthor(string s)
    {
        author.push_back(s);
        nauthor++;
    }
    void removeAuthor(string s)
    {
        vector <string>::iterator it =find(author.begin(),author.end(),s);
        if(it !=author.end())
        {
            author.erase(it);
            nauthor--;
        }
        else
            cout <<s<<" not found in the list of authors";
    }
    bool isAuthor(string s)
    {
        vector <string>::iterator it = find(author.begin(),author.end(),s);
        return(it!=author.end());
    }
    vector <string> getAuthor()
    {
        vector <string> temp;
        if(nauthor>0)
            return author;
        else
            cout<<"No authors added";
            return temp;
    }
    
    void setYearOfPub(string s)
    {
        YearOfPub = s;
    }
    string getYearOfPub()
    {
        return YearOfPub;
    }
    bool isYearOfPub(string s)
    {
        return YearOfPub==s;
    }
    
    int getNAuthor()
    {
        return nauthor;
    }
    void printAuthor()
    {
        if(author.size()==0)
            cout<<"No authors added";
        else
        {
            for(int i=0; i < author.size(); i++)
                cout << author.at(i) << "\n";
        }
    }
};

main(for testing) :

#include "bookType.h"
int main()
{
    vector <string> temp(0,"");
    bookType book1("Charles Darwin",temp,"Penguin Publishiong","ISBN1201231",10,100,"1984");
    cout<<book1.getPrice()<<"\n"<<book1.getYearOfPub()<<"\n"<<book1.getISBN()<<"\n"<<book1.getCopies()<<"\n"<<book1.getTitle()<<"\n";
    book1.addAuthor("Hello");
    book1.addAuthor("Mr Beast");
    book1.printAuthor();
    book1.removeAuthor("Hello");
    book1.printAuthor();
    cout<<book1.isAuthor("Mr Beast");
    vector <string> a = book1.getAuthor();
    cout<<a[0];
    book1.setPrice(10);
    book1.setTitle("Charles Darwin");
    book1.addAuthor("Mike Pence");
    book1.setYearOfPub("1984");
    return 10;
}

I've tested all the methods that I found complex, please let me know if it works!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show...
Use ONLY the classes in this list to draw a Class diagram. The diagram must show all the classes, their attributes, and the relationships between the classes. All the associations must have proper multiplicity constraints indicated. Note that class methods and attribute types are not required.                                                                                                               Domain classes and their attributes Order [date/time, total price, status] Account [full name, address, phone, email] SellerAccount (no attributes) BuyerAccount [credit card] Book [title, ISBN, author, publisher, asking price] BookOnOrder [quantity] Dispute [reason]...
Question 2 The questions in this section are all based on the “Online Book Exchange System...
Question 2 The questions in this section are all based on the “Online Book Exchange System (EyesHaveIt.com)” Case Study on the last page of this document. Read the case study carefully before answering these questions. b) An analyst has identified all the domain classes and their attributes required for the system, as listed below. Use ONLY the classes in this list to draw a Class diagram. The diagram must show all the classes, their attributes, and the relationships between the...
University library management system This case is a simplified (initial draft) of a new system for...
University library management system This case is a simplified (initial draft) of a new system for the University Library. Of course, the library system must keep track of books. Information is maintained about both book titles and the individual book copies. Book titles maintain information about title, author, publisher, and catalog number. Individual copies maintain copy number, edition, publication year, ISBN, book status (whether it is on the shelf or loaned out), and date due back in. The library also...
Plot a UML diagram for the following application. A chain of community libraries run book loan...
Plot a UML diagram for the following application. A chain of community libraries run book loan services. A book can be borrowed from a library of the chain and returned to another library. A book has an ISBN number, a title, some authors, and a year of publication. Books have a loan period limit which is determined by how frequent the books have been borrowed. Books may have multiple copies and each copy has an item number. When all copies...
IN JAVA PLEASE Design and implement an ADT CreditCard that represents a credit card. The data...
IN JAVA PLEASE Design and implement an ADT CreditCard that represents a credit card. The data of the ADT should include Java variables for the customer name, the account number, the next due date, the reward points, and the account balance. The initialization operation should set the data to client-supplied values. Include operations for a credit card charge, a cash advance, a payment, the addition of interest to the balance, and the display of the statistics of the account. Be...
Question 2 The questions in this section are all based on the “Online Book Exchange System...
Question 2 The questions in this section are all based on the “Online Book Exchange System (EyesHaveIt.com)” Case Study on the last page of this document. Read the case study carefully before answering these questions. A system analyst in your team has identified main user goals for the system, as shown below. Use ONLY the goals in this list to draw a Use Case diagram with all the actors and associations required. Goals List Online account registration Searching for book...
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem...
Problem: Certain mathematical problems involve manipulation of the digits within a whole number. One such problem requires that the digits be re-arranged.In this project, we will reverse the order of the digits in a number. Assignment: Design, develop, and test an Object-Oriented C++program that reads a whole number from the user, removes the sign and all leading and trailing zeroes from that number, and then performs the following operations on that number: 1) reverses the digits, 2) sorts the digits...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these...
**[70 pts]** You will be writing a (rather primitive) online store simulator. It will have these classes: Product, Customer, and Store. All data members of each class should be marked as **private** (a leading underscore in the name). Since they're private, if you need to access them from outside the class, you should do so via get or set methods. Any get or set methods should be named per the usual convention ("get_" or "set_" followed by the name of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT