Question
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
code of q1
//Line.h
#ifndef Line_H #define Line_H
#include
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; i ============================================== //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; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started