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

CHAPTER 9 TECHNICALITIES: CLASSES, ETC Book should have members for the ISBN, ti

ID: 3773618 • Letter: C

Question

CHAPTER 9 TECHNICALITIES: CLASSES, ETC Book should have members for the ISBN, title, author, and copyright date. Also store data on whether or not the book is checked out. Create functions for returning those data values. Create functions for checking a book in and out. Do simple validation of data entered into a Book:; for example, accept ISBNs only of the form n-n-n-x where n is an integer and x is a digit or a letter. Store an ISBN as a string. the ISBN numbers are the same for two books. Have != also compare the ISBN numbers. Have a

Explanation / Answer

Answer:

5. Book Class:

struct DATE

{

int day;

int mon;

int y;

DATE()

{

day=0;

mon=0;

y=0;

}

DATE(int dayin,int monin,int yearin)

{

day=dayin;

mon=monin;

year=yearin;

}

};

class Book

{

string ISBN;

string bookTitle;

string bookAuthor;

Date copyRightDate;

bool checkedOut;

public:

Book(string isbn, string bTitle, string bAuthor, DATE cData, bool check)

{

if(checkValidISBN(isbn))

ISBN=isbn;

bookTitle=bTitle;

bookAuthor=bAuthor;

copyRightDate=cData;

checkedOut=check;

}

bool checkValidISBN(string isbn)

{

istringstream s(isbn);

int t=0;

char a=' ';

if(s>>t)

{

s>>a;

if(a=='-')

if(s>>t)

{

s>>a;

if(a=='-')

if(s>>t)

{

s>>a;

if(a=='-')

{

s>a;if(isalnum(a))

return true;

}

}

}

}

return false;

}

string getBookISBN()

{

return ISBN;

}

string getBookTitle()

{

return bookTitle;

}

string getBookAuthor()

{

return bookAuthor;

}

DATE get_CopyRight_Date()

{

return copyRightDate;

}

bool get_Checked_Out

{

return checkedOut;

}

};

6. Add operators to Book Class:

bool operator==(Book& b1)

{

     if(ISBN==b1. getBookISBN())

          return true;

return false;

}

bool operator!=(Book& b1)

{

     if(ISBN!=b1. getBookISBN())

          return true;

return false;

}

ostream& operator<<(ostream& output, Book& b1)

{

output<< " Book Title:"<< b1. getBookTitle()<< endl;

output << " Book Author:" << b1. getBookAuthor()<< endl

output << " Book ISBN:"<< getBookISBN()<< endl;

return output;

}

7. Adding enumerated dataType to Book class:

enum Genre{fiction,nonfiction,periodical,biography,children};

struct DATE

{

int day;

int mon;

int y;

DATE()

{

day=0;

mon=0;

y=0;

}

DATE(int dayin,int monin,int yearin)

{

day=dayin;

mon=monin;

year=yearin;

}

class Book

{

string ISBN;

string bookTitle;

string bookAuthor;

Date copyRightDate;

bool checkedOut;

Genre bookGenre;

public:

Book(string isbn, string bTitle, string bAuthor, DATE cData, bool check,Genre bGenre)

{

if(checkValidISBN(isbn))

ISBN=isbn;

bookTitle=bTitle;

bookAuthor=bAuthor;

copyRightDate=cData;

checkedOut=check;

bookGenre=bGenre;

}

bool checkValidISBN(string isbn)

{

istringstream s(isbn);

int t=0;

char a=' ';

if(s>>t)

{

s>>a;

if(a=='-')

if(s>>t)

{

s>>a;

if(a=='-')

if(s>>t)

{

s>>a;

if(a=='-')

{

s>a;if(isalnum(a))

return true;

}

}

}

}

return false;

}

string getBookISBN()

{

return ISBN;

}

string getBookTitle()

{

return bookTitle;

}

string getBookAuthor()

{

return bookAuthor;

}

DATE get_CopyRight_Date()

{

return copyRightDate;

}

bool get_Checked_Out

{

return checkedOut;

}

Genre getBookGenre()

{

     return bookGenre;

}

bool operator==(Book& b1)

{

     if(ISBN==b1. getBookISBN())

          return true;

return false;

}

bool operator!=(Book& b1)

{

     if(ISBN!=b1. getBookISBN())

          return true;

return false;

}

ostream& operator<<(ostream& output, Book& b1)

{

output<< " Book Title:"<< b1. getBookTitle()<< endl;

output << " Book Author:" << b1. getBookAuthor()<< endl

output << " Book ISBN:"<< getBookISBN()<< endl;

return output;

}

};