Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ only question 2 please code of q1 //Line.h #ifndef Line_H #define Line_H #include using namespace std; class Line { private: string attrib; public: Line();

c++ only question 2 please

image text in transcribed

image text in transcribed

code of q1

//Line.h

#ifndef Line_H #define Line_H

#include using namespace std;

class Line { private: string attrib; public: Line(); Line(string s); void operator=(const Line& l); Line(const Line& l); ~Line(); void set_attrib(string s); string get_attrib(); void print(); void concat(Line &l2); bool HasSameContent(Line &l2); };

#endif

===================================================

//Line.cpp

#include"Line.h"

Line::Line() { attrib = ""; } Line::Line(string s) { attrib = s; } Line::~Line() { attrib = ""; } Line::Line(const Line& l) { attrib = l.attrib; } void Line::operator=(const Line& l) { attrib = l.attrib; } void Line::set_attrib(string s) { attrib = s; } string Line::get_attrib() { return attrib; } void Line::print() { cout

===============================================

//Page.h

#ifndef PAGE_H #define PAGE_H #include"Line.cpp" using namespace std;

class Page { Line arr[30]; int page_number; int num_lines; public: Page(); Page(const Page& p); ~Page(); void set_line(int i,string s); void set_page_number(int n); int get_page_number(); void add_line(string s); void print(); bool HasMoreLines(Page &p2) ; void get_line(int i); int get_num_lines(); void operator=(const Page& p); };

#endif

=====================================================

//Page.cpp

#include "Page.h" Page::Page() { for(int i=0; i

Page::~Page() {

}

void Page::set_line(int i,string s) { if(i

Page::Page(const Page& p) { page_number = p.page_number; num_lines = p.num_lines; for(int i=0; i

void Page::operator=(const Page& p) { page_number = p.page_number; num_lines = p.num_lines; for(int i=0; i

int Page::get_num_lines() { return num_lines; } void Page::set_page_number(int n) { page_number = n; }

int Page::get_page_number() { return page_number; }

void Page::add_line(string s) { if(num_lines

void Page::print() { for(int i=0; i

bool Page::HasMoreLines(Page &p2) { return get_num_lines()>p2.get_num_lines(); }

=========================================================

//Book.h

#ifndef BOOK_H #define BOOK_H #include "Page.cpp" class Book { Page* pages; int current_num; int capacity; public: Book(); Book(const Book& b); ~Book(); int get_numpages(); void AddPage(const Page &p); void print(); bool HasMorePages(Book &B2); bool HasMoreLines(Book &B2); };

#endif

===============================================

//Book.cpp

#include"Book.h"

Book::Book() { current_num = 0; this->capacity = 5; pages = new Page[capacity]; } Book::Book(const Book& b) { capacity = b.capacity; current_num = b.current_num; pages = new Page[capacity]; for(int i=0; i

Book::~Book() { delete[] pages; }

int Book::get_numpages() { return current_num; }

void Book::AddPage(const Page &p) { if(current_num>=capacity) { Page* t_pages = new Page[capacity]; for(int i=0; i

void Book::print() { for(int i=0; i

bool Book::HasMorePages(Book &B2) { return current_num>B2.get_numpages(); } bool Book::HasMoreLines(Book &B2) { int sum1= 0,sum2 =0; for(int i=0; isum2; }

==============================================

//Test_Book.cpp

#include"Book.cpp"

int main() { string arr[18]; char c = 'A'; for(int i=0; iAddPage(pages[i]); } delete b; return 0; }

Object Oriented programming Homework 2 Deadline 3-1-2021 (Firm, no extensions) . Q1: Implement the following classes: Line class, where each line has (22 marks) attribute content (as private string). (2 marks) Default and initializer constructors (4 marks) o O o destructor, (2 marks) O setters and getters (4 marks) Define print function that prints line contents. (2 marks) Void concat(line &/2), which concatenates the two lines contents and empty the received one. (4 marks) O HasSameContentLine &12) which compares two objects and returns back true if they both . o o O O have the same exact content. (4 marks) Page class where each page has (23 marks) two private members: 1) array of 30 lines and 2) page number. (2 marks) The constructor should initialize the lines to empty string and page number to 0. (2 marks) Destructor (2 marks) Setters (lines and page number) and one getter for page number (6 marks) AddLine member function that receives a line object and adds it to current page. The line will be added after last non-empty line. If number of lines is already 30, it will display a message "cannot add line, page is full". (4 marks) print function that prints page lines line by line. (3 marks) Has Morelines(Page &p2) which compares the two pages and return back true if original object has more Lines than object p2. (4 marks) Book class, where each book has (30 marks) private attributes: 1)a dynamic array of pages, 2) the current number of pages. (2 marks) Constructor (2 marks) and copy constructor (4 marks) Destructor (2 marks) Getter for number of pages(2 marks) O O O o o o o AddPage member function. It receives a page object and adds it to the book. Each time a page is added, it is assigned a page number based on sequence of addition. (6 marks) Print function to print the book pages page by page, the function should print a separator line between every two pages. (4 marks) HasMorePages(Book &B2) which compares the two book objects and return back true if original object has more pages than object B2. (4 marks) HasMorelines(Book &B2) which compares the two book objects and return back true if original object has more Lines than object B2. (4 marks) o O You have to separate header from implementation for all classes Q2: Write a main function that does the following: (25 marks) 1. Has array of lines, where array size is 18. Input using loop values inside the objects of lines array. Make your values as the following: for line 1 AAAAAA, for line 2 "BBBBBB, for line 3 "CCCCCC" and so on. (4 marks) 2. define an array of pages of size 6. add 3 lines per page from lines array defined in point 1. First 3 lines go to first page, second 3 lines go to second page and so on. (4 marks) 3. Define two book objects b1, and b2 where b1 has first 2 pages while b2 has last 3 pages. Use AddPage function to add the specified pages for each book. (4 marks) 4. Print the pages inside b2. (1 marks) 5. Print the total number of pages added in both books (b1 and 62). (1 marks) 6. Print which book has more pages, and which book has more lines B1 or B2. (4 marks) 7. Define book class pointer variable. Create a new book object and make the pointer point to it. Use AddPage function to add pages 2,3,4 and 5 to the book. ( 5 marks) 8. Delete last object that was created dynamically. (2 marks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

11.7 Correlation Analysis Hypothesis Test for Correlation

Answered: 1 week ago

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago