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

See page 260 programming exercise 7 data structure using c++ 2nd edition. a. Som

ID: 3865160 • Letter: S

Question

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

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 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 data member.
Include the member functions to perform the various operations on the
objects 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).


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


c. 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.

here is sample output below..

sample output The title of the book is same. The details of the book are: Title: Data Structures Publisher: XYZ Number of copies: 5 ISBN Number: 67837216 Year of Publication: 1995 Price: 90.50 Authors DEF The title of the book is same. The details of the book are: Title: Programming with C Publisher: WXY Number of copies: 5 ISBN Number: 76873216 Year of Publication: 1997 Price: 200.50 Authors GHI JKL The updates have been made The details of the book are: Title: Programming with C Publisher: WXY

Explanation / Answer

#include "bookType.h"
#include <fstream>
int main()
{
   bookType books[5];
   ifstream theFile("books.dat");
   string line;
   string line2;
   double number;
   for (int i = 0; i < 5; i++)
   {

   getline(theFile, line);
   books[i].set_title(line);
   getline(theFile, line);
   books[i].set_ISBN(line);
   getline(theFile, line);
   books[i].set_publisher(line);
   getline(theFile, line);
   books[i].set_year(line);
   theFile >> number;
   theFile.ignore(numeric_limits<streamsize>::max(), ' ');
   books[i].set_price(number);
   theFile >> number;
   theFile.ignore(numeric_limits<streamsize>::max(), ' ');
   books[i].set_numOfcopies(number);
   theFile >> number;
   theFile.ignore(numeric_limits<streamsize>::max(), ' ');
   books[i].set_numOfAuthors(number);
   }
  
   for (int i = 0; i < 5; i++)
   {
       cout << books[i].get_title();
       cout << endl;
       cout << books[i].get_ISBN();
       cout << endl;
       cout << books[i].get_publisher();
       cout << endl;
       cout << books[i].get_year();
       cout << endl;
       cout << books[i].get_price();
       cout << endl;
       cout << books[i].get_numOfcopies();
       cout << endl;
       cout << books[i].get_numOfAuthors();
       cout << endl;
       //books[i].list_authors();
   }
  
   cout << endl;
   std::cin.get();
   return 0;

}