Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Some of the characteristics of a book are the title, author(s), publisher, I

ID: 3864557 • Letter: #

Question

(a) Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. Design the class bookType that defines the book as an ADT.

Each object of the class bookType can hold the following infomratin 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 data member.

Include the member functions to perform the various operations on the object of bookType. For example, the typical 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 and a destructor (if one is needed) don't use any pointers and you won't need a destructor

Write the definitions of the member functions of the class bookType.

Write a program that uses the class bookType and tests the various operations on the objects of class bookType. Declare a vector container of type bookType. Some of the operations that you should perform are to search for a book by its title, search by ISBN, and update the number of copies in stock.

See page 260 programming exercise 7 data structure using c++ 2nd ed. c++

Explanation / Answer

#include<iostream>
#include<bits/stdc++.h> // to include all header file at once
using namespace std;
class booktype
{
string title;
string author;
string publisher;
int isbn;
int price;
int nofcopies;
public:
booktype();
void showtitle();
void settitle();
bool checktitle(string t);
void showauthor();
void setauthor();
bool checkauthor(string au);
void showpublisher();
void setpublisher();
bool checkpublisher(string pub);
void show_nofcopies();
void set_nofcopies();
void update_nofcopies();
int no_ofcopies();
void show_price();
void set_price();
void update_price();
void show_isbn();
void set_isbn();
void update_isbn();
};
booktype::booktype() // constructor
{
cout<< " enter title:";
cin>> title;
cout<< " enter author names:";
cin>> author;
cout<< " enter publisher name:";
cin>> publisher;
cout<< " enter ISBN:";
cin>> isbn;
cout<< " enter price:";
cin>> price;
cout<< " enter no of copies:";
cin>> nofcopies;
}
void booktype::showtitle()
{
cout<< " title is:"<<title<< " ";
}
void booktype::settitle()
{
cout<< " enter title:";
cin>> title;
}
bool booktype::checktitle(string t)
{
if(t==title)
return true;
else
return false;
}
void booktype::showauthor()
{
cout<< " authors are:"<<author<< " ";
}
void booktype::setauthor()
{
cout<< " enter authors:";
cin>> author;
}
bool booktype::checkauthor(string au)
{
if(au==author)
return true;
else
return false;
}
void booktype::showpublisher()
{
cout<< " publisher is:"<<publisher<< " ";
}
void booktype::setpublisher()
{
cout<< " enter publisher:";
cin>> publisher;
}
bool booktype::checkpublisher(string pub)
{
if(pub==publisher)
return true;
else
return false;
}
void booktype::show_nofcopies()
{
cout<< " no of copies:"<< nofcopies;
}
void booktype::set_nofcopies()
{
cout<< " enter no of copies:";
cin>> nofcopies;
}
void booktype::update_nofcopies()
{
cout<< " enter new no of copies:";
cin>> nofcopies;
}
int booktype::no_ofcopies()
{
return nofcopies;
}
void booktype::show_price()
{
cout<< " price of book:"<< price;
}
void booktype::set_price()
{
cout<< " enter price:";
cin>> price;
}
void booktype::update_price()
{
cout<< "enter new price:";
cin>> price;
}
void booktype::show_isbn()
{
cout<< " isbn:"<< isbn;
}
void booktype::set_isbn()
{
cout<< " enter isbn:";
cin>> isbn;
}
void booktype::update_isbn()
{
cout<< " enter new isbn:";
cin>> isbn;
}
int main()
{
string publisher;
int sizevec;
booktype b1;
b1.settitle();
b1.showauthor();
cout<< " enter publisher name:";
cin>> publisher;
if(b1.checkpublisher(publisher))
cout<< "publisher name is write:)";
b1.update_isbn();
vector<booktype> v1;
v1.push_back(b1); // to append an object of class booktype in container vector
sizevec=v1.size(); // returns no of values stored in vector
cout<< " no of values in vector"<< sizevec;
}