1 - 6 //Consider the following classes (Note: You will add additional methods as
ID: 3805743 • Letter: 1
Question
1 - 6//Consider the following classes (Note: You will add additional methods as instructed below) Please separate the class declaration/implementation into separate .h/.cpp files – Line.h/Line.cpp, Page.h/Page.cpp, Book.h/Book.cpp.
class Line
{
private:
char* letters;
public:
Line();
char* getLine()
char getCharAt(int index);
void setLine(char *line);
};
class Page
{
private :
Line* lines;
public:
Page();
Line getLineAt(int index);
void setLineAt(int index,Line line);
};
class Book
{
private:
Page* pages;
public:
Book();
Page getPageAt(int index);
void setPageAt(int index, Page p);
};
int main()
{
//Add all code here
}
If the max number of characters per line is 255, write the default Constructor for the Line class. Write the Copy Constructor for the Line Class. Write the Destructor for the Line class. Write the statement in main (where Add all code here is found) that will create a Line object name “line”. Write the statement that will initialize line to “The brown fox ran thru the hollow log”.
If the max number of lines per page is 64, write the default Constructor for the Page class. Write the Copy Constructor for the Page Class. Write the Destructor for the Page Class. Write the statement in main (beneath your declaration/initialization for Line) that will create a Page object named “page”. Write the statement that will initialize all 64 lines of page to the same line created in question 2.
If the max number of pages per book is 1000, write the default Constructor for the Book class. Write the Copy Constructor for the Book Class. Write the Destructor for the Book Class. Write the statement in main (beneath your declaration/initialization for Page) that will create a Book object named “book”. Write the statement that will initialize the 1st 200 pages of book to the same page created in 3.
Write the statement(s) beneath 4 that will display the 17th letter of the 49th line on the 173rd page of book.
Write the statement(s) that will set the 18th line of the 73rd page of book to “Hello world!”;
Write the statement that will display the 39th line of the 123rd page of book.
1-6 Consider the following classes (Note: Nou will add additional methods as instracted below) Pkagesaparate class Line private: char letters: Line0; char" getLinc0 char getCharAt(int index); void setLine(char line): class Page private Line" lines: public: Page0; Line getLineAt(int index): void setLineAt(int index, Line linex class Book private: Page pages. public: Page getPage/Atint index); void setPageAI(int index. Page p): int main() Add all code here I. If the max number of characters per line is 255, write the default Constructor for the Line class Write the Copy Constructor for the Line Class. Write the Destructor for the Line class. Write the statement (where Add all code here is found that will create a Line objectname"line". Writethe statement that will initialize line to The brown fox ran thruthe hollow log 2. If the max number of lines per page is 64, write the default Constructor for the Page class. Write the Copy Constructor for the Page Class. Write the Destructor for the Page Class. Write the statement beneath your declaration initialization for Line) that will create a Page object named page Write the statement that will initialize all 64 lines of page to the same line created in question 2. 3 If the max number of pages per book is 000, write the default Constructor for the Book class Write the Copy (beneath your declaration i ialization for Page)that will create a Book objectnamed book Write the statement that will initialize the l 200 pages of book to thesame page created in 3. 4. Write the statement(s) beneath 4 that will display the 17 letter of the 49 a line on the 173 page ofbook. 5. Write the statement(s) that will set the 18 Iine of the page of book to "Hello world! will display the 39 line of the 123 page ofbook. 6, Write the statement thatExplanation / Answer
#include<iostream>
#include<string.h>
using namespace std;
class Line
{
private:
char* letters;
public:
Line();
~Line();
Line(const Line &obj);
char* getLine();
char getCharAt(int index);
void setLine(char *line);
};
Line::Line()
{
//cout<<" Calling default constructor of Line class...";
letters= new char[255];
}
Line::Line(const Line &obj)
{
//cout<<" Calling copy constructor of Line class...";
letters=obj.letters;
}
char* Line::getLine()
{
return letters;
}
char Line::getCharAt(int index)
{
return letters[index];
}
void Line::setLine(char *line)
{
if(strlen(line)<=255)
strcpy(letters,line);
else
cout<<"Line too long!";
}
Line::~Line()
{
//cout<<" Calling destructor of Line class...";
delete []letters;
}
class Page
{
private :
Line* lines;
public:
Page();
Page(const Page &obj);
~Page();
Line getLineAt(int index);
void setLineAt(int index,const Line &line);
};
Page::Page()
{
//cout<<" Calling default constructor of Page class...";
lines= new Line[64];
}
Page::Page(const Page &obj)
{
//cout<<" Calling copy constructor of Page class...";
lines=obj.lines;
}
Line Page::getLineAt(int index)
{
return lines[index];
}
void Page::setLineAt(int index,const Line &line)
{
lines[index]=line;
}
Page::~Page()
{
//cout<<" Calling destructor of Page class...";
delete []lines;
}
class Book
{
private:
Page* pages;
public:
Book();
Book(const Book &obj);
~Book();
Page getPageAt(int index);
void setPageAt(int index,const Page &page);
};
Book::Book()
{
//cout<<" Calling default constructor of Book class...";
pages= new Page[1000];
}
Book::Book(const Book &obj)
{
//cout<<" Calling copy constructor of Page class...";
pages=obj.pages;
}
Page Book::getPageAt(int index)
{
return pages[index];
}
void Book::setPageAt(int index,const Page &page)
{
pages[index]=page;
}
Book::~Book()
{
//cout<<" Calling destructor of Book class...";
delete []pages;
}
int main()
{
Line line;
char test[]="The brown fox ran through the hollow log.";
line.setLine(test);
cout<<line.getLine();
Page page;
for(int i=0;i<64;i++)
page.setLineAt(i,line);
Page page;
for(int i=0;i<64;i++)
page.setLineAt(i,line);
Book book;
for(int i=0;i<64;i++)
book.setPageAt(0,page);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.