C++ linked lists | Computer Science homework help



1. The declaration of the ReadingList class has been changed, in the private area, to use a std::list instead of an array as its implementing data structure.

Because a std::list can grow arbitrarily long, there is no need to pre-allocate a space to hold the books, so the parameters and function for tracking the capacity have been removed.

2. Your task is to follow through on that change, making the necessary alterations to readingList.h and readingList.cpp to make this a working class. The necessary changes have already been made to the unit tests and to the main mergeLists.cpp application.

3. The major difference between lists and the earlier sequential structures that we have looked at is that elements are accessed via iterators instead of integer-based indices. Accordingly, you will need to: 

– Rewrite the indexing-based code in readingList.cpp with iterator-based code.

– Remove the indexing-based get function from readingList.h and add appropriate declarations of iterator and const_iterator types and associated functions allowing access to a ReadingList object’s sections.

4. To improve the usability of the ReadingList class, you will also need to add

– A constructor to allow ReadingList objects to be constructed from a pair of iterators denoting a range of Book values from some arbitrary container.

– A constructor to allow ReadingList objects to be constructed from an initializer_list of books.

5. Your code will be evaluated both on its ability to function correctly within the mergeLists application and on its ability to pass the various unit tests provided.

– In the test report, tests 0…7 test the mergeLists application. Tests numbered 8…25 check the unit tests.

– Each even-numbered test checks for correct behavior of the code.

– Each odd-numbered test checks to see if that same behavior is correct and entails no memory leaks or other common pointer/memory handling problems.

6. Submit files readingList.h and readingList.cpp

Problem Description: 

This assignment centers on a program that accepts as input two lists of e-books (derived from Project Gutenberg) and merges the two into one, eliminating any duplicate entries during the process. Each e-book is is described by three fields, an ID, the author info, and the title. In input and output, these appear together on a line separated by tab (“t”) characters.

For example, given the input

etext19640  Twain, Mark, 1835-1910   Adventures of Huckleberry Finn
etext13 Carroll, Lewis, 1832-1898   The Hunting of the Snark
etext9038   Twain, Mark, 1835-1910    The Adventures of Tom Sawyer


etext9038   Twain, Mark, 1835-1910    The Adventures of Tom Sawyer
etext20595  Twain, Mark, 1835-1910   The Awful German Language
etext23717  Carroll, Lewis, 1832-1898    Jabberwocky

the merge will be

etext13 Carroll, Lewis, 1832-1898   The Hunting of the Snark
etext19640  Twain, Mark, 1835-1910   Adventures of Huckleberry Finn
etext20595  Twain, Mark, 1835-1910   The Awful German Language
etext23717  Carroll, Lewis, 1832-1898    Jabberwocky
etext9038   Twain, Mark, 1835-1910    The Adventures of Tom Sawyer

The output is sorted by the project Gutenberg ID (the “etext…” field).

You are being supplied with a nearly complete working version of the mergeLists application.

Your task is to complete the implementation of the ReadingList class in accordance with the principles for robust and reusable ADTs as described in the lecture notes. You must use a dynamically allocated array as the basis for storing books within the reading list.

System Tests: 

The program takes its input from two files named in the command line and produces its output on standard out (cout). For example, if you have compiled the program into an executable named “mergeLists”, and had saved the sample input above in files tinyList.txt and tinyList2.txt in the same directory, you could run the program as

./mergeLists tinyList.txt tinyList2.txt

If you are working in Windows, use “.” instead of “./”. Of course, if you have your files in different directories or use different names, you will need to adjust your paths in the above command accordingly.

In general, you are responsible for designing and running your own systems tests.

That said, you have been provided with several input files of various lengths that you can use “as is” or chop up and recombine as you see fit.

Unit Tests: 

The unit tests will form a separate executable, named unittest. It can be run without parameters to run all tests on the ReadingList class.

You can, however, list one or more test names as parameters to run those tests only. For example, if you are failing the testRLRemove test, run

./unittest testRLRemove

to focus on just that one test. This can be very useful when debugging your code, because the unit tests are simpler and will get to your Faculty code a great deal more directly than the full application.

You can also abbreviate test names to run all tests beginning with a string.

For example,

./unittest testRLR

would suffice to run that same single test.


  • You may use any of the techniques covered for manipulating data via iterators, including range-based loops, the auto keyword, and generic functions from the next lesson, if you are reading ahead.
  • In designing the iterators for the ReadingList class, consider carefully the options of creating an new iterator class versus reusing an existing iterator type. 
  • The ReadingList class keeps its Books in order. Allowing application code to alter or      reassign the internal sections via an iterator, e.g.,

· ReadingList::iterator it = myReadingList.begin();

· *it = Book(“99999”, “Zzarg, Jonathan”, “The Last Book Ever Written”);

would risk breaking that ordering, making any code that relies on the ordering fail.

That means that ReadingList needs to be one of those classes that use a single const iterator type as both iterator and const_iterator.

  • You may find it a much more efficient use of your time to focus on passing the unit tests first and worry about system testing the full mergeLists application afterwards.


make all 

touch book.d

touch counted.d

touch mergeLists.d

touch readingList.d

touch sanityCheck.d

touch testReadingList.d

touch unittest.d

cat book.d counted.d mergeLists.d readingList.d sanityCheck.d testReadingList.d unittest.d > make.dep

g++ -g -std=c++17 -MMD -pthread -D_GLIBCXX_DEBUG -Wall -o book.o -c book.cpp

g++ -g -std=c++17 -MMD -pthread -D_GLIBCXX_DEBUG -Wall -o counted.o -c counted.cpp

g++ -g -std=c++17 -MMD -pthread -D_GLIBCXX_DEBUG -Wall -o mergeLists.o -c mergeLists.cpp

mergeLists.cpp: In function ‘ReadingList mergeReadingLists(const ReadingList&, const ReadingList&)’:

mergeLists.cpp:25:39: error: ‘const class ReadingList’ has no member named ‘begin’

   25 |  ReadingList::const_iterator i = cat1.begin();

      |                                       ^~~~~

mergeLists.cpp:26:39: error: ‘const class ReadingList’ has no member named ‘begin’

   26 |  ReadingList::const_iterator j = cat2.begin();

      |                                       ^~~~~

mergeLists.cpp:27:19: error: ‘const class ReadingList’ has no member named ‘end’

   27 |  while (i != cat1.end() && j != cat2.end())

      |                   ^~~

mergeLists.cpp:27:38: error: ‘const class ReadingList’ has no member named ‘end’

   27 |  while (i != cat1.end() && j != cat2.end())

      |                                      ^~~

mergeLists.cpp:29:20: error: invalid type argument of unary ‘*’ (have ‘ReadingList::const_iterator’ {aka ‘int’})

   29 |   const Book& b1 = *i;

      |                    ^~

mergeLists.cpp:30:20: error: invalid type argument of unary ‘*’ (have ‘ReadingList::const_iterator’ {aka ‘int’})

   30 |   const Book& b2 = *j;

      |                    ^~

mergeLists.cpp:42:19: error: ‘const class ReadingList’ has no member named ‘end’

   42 |  while (i != cat1.end())

      |                   ^~~

mergeLists.cpp:44:14: error: invalid type argument of unary ‘*’ (have ‘ReadingList::const_iterator’ {aka ‘int’})

   44 |   result.add(*i);

      |              ^~

mergeLists.cpp:47:19: error: ‘const class ReadingList’ has no member named ‘end’

   47 |  while (j != cat2.end())

      |                   ^~~

mergeLists.cpp:49:14: error: invalid type argument of unary ‘*’ (have ‘ReadingList::const_iterator’ {aka ‘int’})

   49 |   result.add(*j);

      |              ^~

make: *** [makefile:54: mergeLists.o] Error 1

“make all” terminated with exit code 2. Build might be incomplete.

14:37:11 Build Failed. 11 errors, 0 warnings. (took 4s.338ms)

Assignment Help
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.


Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.


Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.


Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.


Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.