Extend the above book class so that book class also contains publisher name, author name and book name, now create three more constructor in the new book class, so that we can create new object when:
a)we have all the information about a book.
b)we don't know the publisher's name and number of pages in the book.
c)we don't have any information about the book ( default constructor )
#include <iostream.h>
//using namespace std
class Book
{
int PageCount;
int CurrentPage;
public:
// Constructor
Book (int NumPages);
// Destructor
~Book ()
{
cout<<"I completed this book\n";
}
void bookMark(int PageNumber);
int getBookMark( void );
};
Book::Book(int NumPages)
{
PageCount=(NumPages);
cout<<"I have started reading a new book\n";
}
The part ": PageCount( 0 ), CurrentPage( 0 )" is called a initialization list and it is important that the variables listed there are in the order in which they are declared in the class:
1 2 3 4
class Book
{
int PageCount;
int CurrentPage;
edit: just to clarify, you can sort of think of the : PageCount( 0 ), CurrentPage( 0 ) as
1 2
PageCount = 0;
CurrentPage = 0;
if that helps...
Another constructor you could use would be a copy constructor. Google it! Also google default constructor and initialization list.
If you're too lazy to google that stuff or just don't have any interest you should reconsider your... uh... major