Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with To do 2 and 3 section Booklist::Booklist( const std::initializer_list & initlist ) : _books_vector ( initList.begin(), initlist.end()), _books_dl_list( initlist.begin(), initList.end()), _books_sl_list(

image text in transcribed

I need help with To do 2 and 3 section

image text in transcribedimage text in transcribed

Booklist::Booklist( const std::initializer_list & initlist ) : _books_vector ( initList.begin(), initlist.end()), _books_dl_list( initlist.begin(), initList.end()), _books_sl_list( initlist.begin(), initList.end()) // Unlike the other containers that are expandable, the array has a fixed capacity N. copy only the first N elements of the // initialization list into the array. for( auto p = initList.begin(); _books_array_size & rhs ) { W TO-DO (2) VI III Concatenate the right hand side book list of books to this list by repeatedly inserting at the bottom of this book list. /// The input type is a container of books accessible with iterators like all the other containers. The constructor above gives /// an example. Use Booklist::insert() to insert at the bottom. WIT/ END-TO-DO (2) // Verify the internal book list state is still consistent amongst the four containers if( ! containersAreConsistant()) throw Booklist:: Invalid Internalstate_Ex( "Container consistency error" exception_location ); return *this; Booklist & Booklist::operator+=( const Booklist & rhs ) { VIII TO-DO (3) /// /// Concatenate the right hand side book list of books to this list by repeatedly inserting at the bottom of this book list. /// All the rhs containers (array, vector, list, and forward_list) contain the same information, so pick just one to traverse. /// Walk the container you picked inserting its books to the bottom of this book list. Use Booklist::insert to insert at the /// bottom. ///////// END-TO-DO (3) ///////// // Verify the internal book list state is still consistent amongst the four containers if(!containersAreConsistant()) throw Booklist:: Invalid Internalstate_Ex( "Container consistency error" exception_location ); return *this; #include // find(), move(), move_backward(), equalo, swapo, lexicographical_compare #include // size_t #include #include // setw() #include // distance(), next( #include // logic_error #include #include "Book.hpp" #include "Booklist.hpp" 10 10 11 11 19 12 13 13 1 14 15. 15 16. 16 17 17 18 18 19 19 20 // As a rule, I strongly recommend avoiding macros, unless there is a compelling reason this is such a case. This really does need 11 to be a macro and not a function due to the way the preprocessor expands the source code location information. It's important to 1/ have these expanded where they are used, and not here. But I just can't bring myself to writing this, and getting it correct, 1/ everywhere it is used. Note: C++20 will change this technique with the introduction of the source_location class. Also note the [// usage of having the preprocessor concatenate two string literals separated only by whitespace. #define exception_location " detected in function "*" + std::string(_func_) + "***"* " at line " + std::to_string( _LINE__ " in file " _FILE ** Private implementations, types, and objects bool Booklist:: containersAreConsistant() const // Sizes of all containers must be equal to each other if( _books_array_size != _books_vector.size() != || _books_array_size = -books_si_list-size()) return false; 40 41 // Element content and order must be equal to each other auto current_array_position _books_array.cbegin(); auto current_vector_position _books_vector .cbegin(); auto current_d1_list_position _books_dl_list.cbegin(); auto current_s1_list_position = _books_51_list.cbegin(); . while( current_vector_position != _books_vector.cend()) { if( *current_array_position != *current_vector_position *current_array_position != *current_di_list_position 46 || current_array_position I = = current__list_position return false; // Advance the iterators to the next element in unison ++current_array_position; ++current_vector_position; Hcurrent_dl_list_position; +current_si_list_position; } return true; // Calculate the size of the singly linked list on demand std::size_t Booklist:: books_sl_list_size() const W TO-DO (1) 11/ Some implementations of a singly linked list maintain the size (number of elements in the list). std:: forward_list does /// not. The size of singly linked list must be calculated on demand by walking the list from beginning to end counting the Il number of elements visited. The STL's std::distance() function does that, or you can write your own loop. auto iterator = _books_s1_list.begin(); auto end_iterator = _books_s1_list.end(); std::size_t size = 0; while (iterator != end_iterator) std::distance(iterator, end_iterator); /// END-TO-DO (1) ////// Constructors, destructor, and assignment operators ****************************** ******/ // Rule of 6 - I wanted a tailored assignment operator, so I should (best practice) write the other too Booklist::Booklist = default; Booklist:: Booklist( const Booklist & other ) Booklist:: BookList Booklist && other ) = default; = default; Booklist & Booklist::operator=( Booklist rhs) Booklist & Booklist::operator=( Booklist && rhs ) { swap( rhs ); return *this; } = default; Booklist::-Booklist() = default; Booklist::Booklist( const std::initializer_list & initlist ) : _books_vector ( initList.begin(), initList.end()), _books_di_list( initList.begin(), initlist.end() ), _books_sl_list( initlist.begin(), initlist.end()) // Unlike the other containers that are expandable, the array has a fixed capacity N. copy only the first N elements of the Ti // initialization list into the array. for( auto p = initlist.begin(); _books_array_size & initlist ) : _books_vector ( initList.begin(), initlist.end()), _books_dl_list( initlist.begin(), initList.end()), _books_sl_list( initlist.begin(), initList.end()) // Unlike the other containers that are expandable, the array has a fixed capacity N. copy only the first N elements of the // initialization list into the array. for( auto p = initList.begin(); _books_array_size & rhs ) { W TO-DO (2) VI III Concatenate the right hand side book list of books to this list by repeatedly inserting at the bottom of this book list. /// The input type is a container of books accessible with iterators like all the other containers. The constructor above gives /// an example. Use Booklist::insert() to insert at the bottom. WIT/ END-TO-DO (2) // Verify the internal book list state is still consistent amongst the four containers if( ! containersAreConsistant()) throw Booklist:: Invalid Internalstate_Ex( "Container consistency error" exception_location ); return *this; Booklist & Booklist::operator+=( const Booklist & rhs ) { VIII TO-DO (3) /// /// Concatenate the right hand side book list of books to this list by repeatedly inserting at the bottom of this book list. /// All the rhs containers (array, vector, list, and forward_list) contain the same information, so pick just one to traverse. /// Walk the container you picked inserting its books to the bottom of this book list. Use Booklist::insert to insert at the /// bottom. ///////// END-TO-DO (3) ///////// // Verify the internal book list state is still consistent amongst the four containers if(!containersAreConsistant()) throw Booklist:: Invalid Internalstate_Ex( "Container consistency error" exception_location ); return *this; #include // find(), move(), move_backward(), equalo, swapo, lexicographical_compare #include // size_t #include #include // setw() #include // distance(), next( #include // logic_error #include #include "Book.hpp" #include "Booklist.hpp" 10 10 11 11 19 12 13 13 1 14 15. 15 16. 16 17 17 18 18 19 19 20 // As a rule, I strongly recommend avoiding macros, unless there is a compelling reason this is such a case. This really does need 11 to be a macro and not a function due to the way the preprocessor expands the source code location information. It's important to 1/ have these expanded where they are used, and not here. But I just can't bring myself to writing this, and getting it correct, 1/ everywhere it is used. Note: C++20 will change this technique with the introduction of the source_location class. Also note the [// usage of having the preprocessor concatenate two string literals separated only by whitespace. #define exception_location " detected in function "*" + std::string(_func_) + "***"* " at line " + std::to_string( _LINE__ " in file " _FILE ** Private implementations, types, and objects bool Booklist:: containersAreConsistant() const // Sizes of all containers must be equal to each other if( _books_array_size != _books_vector.size() != || _books_array_size = -books_si_list-size()) return false; 40 41 // Element content and order must be equal to each other auto current_array_position _books_array.cbegin(); auto current_vector_position _books_vector .cbegin(); auto current_d1_list_position _books_dl_list.cbegin(); auto current_s1_list_position = _books_51_list.cbegin(); . while( current_vector_position != _books_vector.cend()) { if( *current_array_position != *current_vector_position *current_array_position != *current_di_list_position 46 || current_array_position I = = current__list_position return false; // Advance the iterators to the next element in unison ++current_array_position; ++current_vector_position; Hcurrent_dl_list_position; +current_si_list_position; } return true; // Calculate the size of the singly linked list on demand std::size_t Booklist:: books_sl_list_size() const W TO-DO (1) 11/ Some implementations of a singly linked list maintain the size (number of elements in the list). std:: forward_list does /// not. The size of singly linked list must be calculated on demand by walking the list from beginning to end counting the Il number of elements visited. The STL's std::distance() function does that, or you can write your own loop. auto iterator = _books_s1_list.begin(); auto end_iterator = _books_s1_list.end(); std::size_t size = 0; while (iterator != end_iterator) std::distance(iterator, end_iterator); /// END-TO-DO (1) ////// Constructors, destructor, and assignment operators ****************************** ******/ // Rule of 6 - I wanted a tailored assignment operator, so I should (best practice) write the other too Booklist::Booklist = default; Booklist:: Booklist( const Booklist & other ) Booklist:: BookList Booklist && other ) = default; = default; Booklist & Booklist::operator=( Booklist rhs) Booklist & Booklist::operator=( Booklist && rhs ) { swap( rhs ); return *this; } = default; Booklist::-Booklist() = default; Booklist::Booklist( const std::initializer_list & initlist ) : _books_vector ( initList.begin(), initList.end()), _books_di_list( initList.begin(), initlist.end() ), _books_sl_list( initlist.begin(), initlist.end()) // Unlike the other containers that are expandable, the array has a fixed capacity N. copy only the first N elements of the Ti // initialization list into the array. for( auto p = initlist.begin(); _books_array_size

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

Step: 3

blur-text-image

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