Book Class

I have to make a Book class with members for the ISBN, title, author, and copyright, as well as checked in/out status. Functions that return those data value has to be made, as well as a status checker. The thing I'm having most problem figuring out is that ISBN has to be of the form integer-integer-integer-integer-char.

So far, this is what I have, copying from the Date class example the book gave me =(.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Book{
public:
	enum Genre{
	fiction = 0, nonfiction, periodical, biography, children
	};
	
	class Invalid{
		//...
	};
	
	Book(int isbn, string author, string title, string copyright, Genre genre, string status)
	Book();
	
	int isbn(); const{return isbn;}
	string author(); const{return author;}
	string title(); const{return title;}
	string copyright(); const{return copyright;}
	Genre genre(); const{return genre;}
	string status(); const{return status;}
private:
	int isbn;
	string author;
	string title;
	string copyright;
	Genre genre;
	string status;	
};


To be honest, I have no idea exactly what the book is asking for, nor what I'm doing.
There are a couple of ISBN formats, depending on the year of the book. But for your program, you probably don't care too much about that. (More here: http://en.wikipedia.org/wiki/International_Standard_Book_Number)

There are four parts to the ISBN: Group, Publisher, Title, and Check Digit. All four parts are numbers except the last one. It is a check digit modulo base 11. Because there is no way to represent 11 as one character in base 10, an 'X' is used in the case of a check digit being 11.

For this program, the easiest way to store the ISBN is as a character array.
When the book asked for ISBN, it meant the regular 13 digit code. However, it also asks for the actual title/copyright date/checked in status/etc... In other words, when I call for a Book A, it's supposed to output

123-456-789-101-b, William Shakespeare, Romeo and Juliet 5th Edition, Fiction, 5/5/2005, checked out

Something along that line...
In other words, when I call for a Book A, it's supposed to output

123-456-789-101-b, William Shakespeare, Romeo and Juliet 5th Edition, Fiction, 5/5/2005, checked out


First, as kooth has mentioned, you need to re-design how you want to hold the isbn variable. Do you want a character array or C++ string ?

Second, what do you mean when I call for a Book A, do you mean
1
2
3
4
5
6
7
8
9
Book bookA; 
bookA.isbn(); //it is supposed to output "123-456-789-101-b, William Shakespeare, Romeo and 
//Juliet 5th Edition, Fiction, 5/5/2005, checked out"

OR

Book bookA; 
cout << bookA; //it is supposed to output "123-456-789-101-b, William Shakespeare, Romeo 
//and Juliet 5th Edition, Fiction, 5/5/2005, checked out" 

Last edited on
@sohguanh
It's the latter which I believe the book asks for. As to the isbn variables, I wouldn't know how to set them as an array of characters. But I think that string is the solution, but since it asks to check for integer or character, I guess I have to manually use a code to check if a string qualifies for either.

Here are the exact instructions; like I said, I'm not entirely sure what it means.

This exercise and the next few require you to design and implement a Book class, such as you can imagine as part of software for a library. Class 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 letter.

Right now just playing around with codes individually to see if they work. But when I take class into consideration, I get a plethora of errors. xD. Oh well, one step at a time.

You could define the ISBN as a string. I'm not going to reproduce your entire class here, just some suggested changes:

1
2
3
4
5
6
7
8
9
10
11

class Book
{
public:
    Book( string isbn, string author, string title, string copyright, Genre genre, string status );

private:
    string isbn;

};


Then in your constructor, add validation of the isbn format:

1
2
3
4
5
6
7
8
9

Book::Book( string isbn, string author, string title, string copyright, Genre genre, string status )
{
/*    Validate isbn for the proper format here:    */

}
    /*    ctor()    */
 
@krad,

I am also using Stroustrup's book to teach myself C++ programming. I did the same exercise last month and asked for help on this forum. I think the title of my thread was "Constructive Criticism Appreciated". I think I posted it 2 or 3 weeks ago. If you find the thread you can look at my code and the suggestions for improvement that forum members posted in reply. That should help you with writing your own program for the exercise.

As for the ISBN, use the format that Stroustrup indicated in the exercise, n-n-n-x. The letter 'n' represents ONE INTEGER, not a number of any length. So an example of an ISBN for this exercise is '5-9-0-q', defined as a string. Remember the KISS principle and the fact we are learning programming, not library science.
Topic archived. No new replies allowed.