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

17.(28 pts) Book with Pages (Parts a -c). Let\'s say we need to design two class

ID: 3730219 • Letter: 1

Question

17.(28 pts) Book with Pages (Parts a -c). Let's say we need to design two classes, one named Page and one named Book. Each Page consists of an integer page number and no more than 500 English characters. The sequence of characters on a Page is always terminated by the null character. A Book consists of a title with no more than 50 characters (terminated by a null character) and no more than 650 Pages. (10 pts) Declare the Page class based on the description above. There are many operations that we could define for a Page, but we are only going to look at a subset for this problem. All attributes should be private. The class should declare the following member operations/functions only: a. i. fi. (2 pts) A constructor with one parameter for setting the page number (2 pts) A const function called getPageNumber () for getting the page number ifi. (2 pts) A const function called getIsCurrentPage for getting the status of the page, i.e if it is the current page being read (true) or not (false (2 pts) A function called printPage () for displaying each character on the page to the screen (should not be done by overloading the stream insertion operator). This function should not accept any arguments and should not return a value. iv. class Page public: // Should contain four prototypes/declarations retum misCane Poge Nunber P t Page Number( ) in ge retum Roge Number private: I/ Should contain three attributes- one has been provided below bool mlsCurrentPage;/ true if this page is the current one being viewed; false otherwise /1 1 pt / data member 2 data members required! int poge Number char Cortent

Explanation / Answer

Page Class:

class Page
{
public :
//Member functions

//Constructor with one parameter i.e. set page number only
Page(int pgNum);

//return page number
int getPageNumber() const;

//return true if page is current page else return false
bool getIsCurrentPage();

//display content of page
void printPage();

private :
int mPageNumber; //hold current page number value
bool mIsCurrentPage; //true if this page is the current one being viewed; false otherwise
char mContent[500]; //contain content of page i.e. characters per page
};

Page::Page(int pgNum)
{
mPageNumber = pgNum;
}

int Page::getPageNumber() const
{
return mPageNumber;
}

bool Page::getIsCurrentPage()
{
return mIsCurrentPage;
}

void Page::printPage()
{
//cout write(char[], length of array)
cout.write(mContent, strlen(mContent));
}

---------------------------------------------------------

Book Class :

class Book
{
public:
//Function to find next page number
int turnPage();

private: //member variables
char mTitle[50];
int mNumPages;
Page mBook[650];
};


int Book::turnPage()
{
for(int i = 1; i <= mNumPages ; i++)
{
//Check for current page
//using getIsCurrentPage to find out current page
if(mBook[i - 1].getIsCurrentPage()) //Array index start with zero thats why (i - 1) because i start from 1 to num pages
{
//check if next page number exceed the number of pages
//if true return start page i.e. page number 1
if(i >= mNumPages)
return 1;
else //Return next page number
return i;
}
}

//if no current page found return start page
return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote