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

1. Design a class bookType that defines the book as an ADT. ? Create a class dia

ID: 655375 • Letter: 1

Question

1. Design a class bookType that defines the book as an ADT. ? Create a class diagram ? Create a class specification worksheet 2. 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. 3. 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 and a destructor (if one is needed). 4. Write the definitions of the member functions of the class bookType. 5. Write a program, bookTest1.cpp, that uses the class bookType and tests various operations on the objects of the class bookType. Declare an array of components 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 of a book. Part 2) You will design a class memberType. 1. Each object of memberType can hold the name of a person, member ID, number of books bought, and amount spent. 2. Include the member functions to perform the various operations on the objects of memberType

Explanation / Answer

Code:

#include <iostream>
#include <string>
# include <fstream>
using namespace std;
class bookType
{
private:
string title;
string author[4];
string publisher;
string ISBN;
double price;
int copies;
int authorCount;
public:
bookType();

bookType(string, string, string, double, int, int, string[]);

string getTitle() const;

string getPublisher() const;

string getISBN() const;

double getPrice() const;

int getCopies() const;

int getAuthorCount() const;

void getAuthors(string a[]);

void setTitle(string t = "");

void setPublisher(string p = "");

void setISBN(string isbn = "");

void setPrice(double p = 0.0);

void setCopies(int c = 0);

void setAuthorCount(int ac = 0);

void setAuthors(string a[], int size);

void incrementCopies();


void updateCopies(int a);

bool updateAuthorCount();

bool equalsTitle(string t);

bool equalsISBN(string isbn);

void showTitle() const;

void showPublisher() const;

void showISBN() const;

void showPrice() const;

void showCopies() const;

void showAuthorCount() const;

void showAuthors() const;

void showBookInfo() const;

};

bookType::bookType()
{

setTitle();
setPublisher();
setISBN();
setPrice();
setCopies();
setAuthorCount();
}

bookType::bookType(string t, string pub, string isbn, double p, int c, int ac, string a[])
{

setTitle(t);
setPublisher(pub);
setISBN(isbn);
setPrice(p);
setCopies(c);
setAuthorCount(ac);
setAuthors(a, getAuthorCount());
}
string bookType::getTitle() const
{
return title;
}

string bookType::getPublisher() const
{
return publisher;
}

string bookType::getISBN() const
{
return ISBN;
}

double bookType::getPrice() const
{
return price;
}

int bookType::getCopies() const
{
return copies;
}

int bookType::getAuthorCount() const
{
return authorCount;
}
void bookType::getAuthors(string a[])
{
for(int i=0;i < authorCount;i++)
{
   if(author[i] != "" || author[i] != "")
    a[i] = author[i];
}
}

void bookType::setTitle(string t)
{
title = t;
}

void bookType::setPublisher(string p)
{
publisher = p;
}

void bookType::setISBN(string isbn)
{
ISBN = isbn;
}

void bookType::setPrice(double p)
{
price = p;
}

void bookType::setCopies(int c)
{
copies = c;
}

void bookType::setAuthorCount(int ac)
{
authorCount = ac;
}

void bookType::setAuthors(string a[], int size)
{
for(int i=0; i < size; i++)
{
   author[i] = a[i];
}
}

void bookType::incrementCopies()
{
copies++;
}

void bookType::updateCopies(int a)
{
copies += a;
}

bool bookType::updateAuthorCount()
{
bool rslt = false;

if(authorCount < 4)
{
   authorCount++;
   rslt = true;
}
return rslt;
}

bool bookType::equalsTitle(string t)
{
bool rslt;
if(title == t)
   rslt = true;
else
   rslt = false;
return rslt;
}

bool bookType::equalsISBN(string isbn)
{
bool rslt;
if(ISBN == isbn)
   rslt = true;
else
   rslt = false;
return rslt;
}

void bookType::showTitle() const
{
cout << "Title: " << title << endl;
}

void bookType::showPublisher() const
{
cout << "Publisher: " << publisher << endl;
}

void bookType::showISBN() const
{
cout << "ISBN: " << ISBN << endl;
}

void bookType::showPrice() const
{
cout << "Price: $" << price << endl;
}

void bookType::showCopies() const
{
cout << "Copies in stock: " << copies << endl;
}

void bookType::showAuthorCount() const
{
cout << "No. of Authors: " << authorCount << endl;
}

void bookType::showAuthors() const
{
for(int i=0; i < authorCount; i++)
{
   if(author[i] != "" || author[i] != "")
    cout << "Author: " << author[i] << endl;
}
}
void bookType::showBookInfo() const
{
showTitle();
showPublisher();
showISBN();
showPrice();
showCopies();
showAuthors();
}
int SearchTitle(bookType[], int, string, int&);
int SearchISBN(bookType[], int, string, int&);
int main()
{
int noOfBooks = 0;
bookType Programming[100];
Programming[0].setTitle("C++ Programming");
Programming[0].setPublisher("Thomson");
Programming[0].setISBN("0-619-16042-X");
Programming[0].setPrice(49.95);
Programming[0].setCopies(10);
Programming[0].setAuthorCount(1);
string cppAuthors[] = {"D.S. Malik"};
Programming[0].setAuthors(cppAuthors, Programming[0].getAuthorCount());
noOfBooks++;
Programming[1].setTitle("VB.Net Programming");
Programming[1].setPublisher("Thomson");
Programming[1].setISBN("0-7895-6549-8");
Programming[1].setPrice(39.95);
Programming[1].setCopies(20);
Programming[1].setAuthorCount(3);
string vbAuthors[] = {"Gary B. Shelly", "Thomas J. Cashman", "Jeffrey J. Quasney"};
Programming[1].setAuthors(vbAuthors, Programming[1].getAuthorCount());
noOfBooks++;
string gameAuthors[] = {"Michael Morrison", "David Morrison"};
bookType GameProg("Game Programming", "SAMS", "0-672-32461-X", 29.95, 30, 2, gameAuthors);
Programming[2].setTitle(GameProg.getTitle());
Programming[2].setPublisher(GameProg.getPublisher());
Programming[2].setISBN(GameProg.getISBN());
Programming[2].setPrice(GameProg.getPrice());
Programming[2].setCopies(GameProg.getCopies());
Programming[2].setAuthorCount(GameProg.getAuthorCount());
Programming[2].setAuthors(gameAuthors, Programming[2].getAuthorCount());
noOfBooks++;
cout << " Search by Title" << endl;
cout << "--------------------" << endl;
int index = 0;
int matches = SearchTitle(Programming, noOfBooks, "Game Programming", index);
if(matches)
{
cout << " Book(s) Found by Title! No. of matches: " << matches << endl;
Programming[index].showBookInfo();
}
else
cout << " Book(s) not found by Title!" << endl;

cout << " Search by ISBN" << endl;
cout << "--------------------" << endl;
index = 0;
matches = SearchISBN(Programming, noOfBooks, "0-619-16042-X", index);
if(matches)
{
cout << " Book(s) Found by ISBN! No. of matches: " << matches << endl;
Programming[index].showBookInfo();
}
else
cout << " Book(s) not found by ISBN!" << endl;

Programming[1].updateCopies(20);
cout << " No. of copies after update for book at index 1: " << Programming[1].getCopies() << endl;

if(Programming[0].updateAuthorCount())
{
cout << " Update author count successfull! Count is: " << Programming[0].getAuthorCount() << endl;
}
else
cout << " Update author count failure!" << endl;


string newAuthors[] = {"D.S. Malik", "Emmanuel Morales"};
Programming[0].setAuthors(newAuthors, 2);

cout << " Display all books registered in system" << endl;
cout << "-------------------------------------------------" << endl;
for(int i = 0; i < noOfBooks; i++)
{
cout << " Book No. : " << i + 1 << endl;
cout << "-------------------" << endl;
Programming[i].showBookInfo();
cout << endl;
}
cin.get();
return 0;
}

int SearchTitle(bookType b[], int numBooks, string t, int &index)
{
int count = 0;

for(int i=0; i < numBooks; i++)
{
if(b[i].equalsTitle(t))
{
   count++;
   index = i;
}
}
return count;
}
int SearchISBN(bookType b[], int numBooks, string isbn, int &index)
{
int count = 0;
for(int i=0; i < numBooks; i++)
{
if(b[i].equalsISBN(isbn))
{
   count++;
   index = i;
}
}
return count;
}