C++ linked lists | Computer Science homework help

  

Instructions: 

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

and

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.

Notes: 

  • 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.

CURRENT ERRORS: 

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)

Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more