Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Requirements You are to provide an implimentation of a list class within the namespace lib, i.e., lib:: list. Define the list class in the

image text in transcribedimage text in transcribedimage text in transcribed

Program Requirements You are to provide an implimentation of a list class within the namespace lib, i.e., lib:: list. Define the list class in the file List.hpp and List.cpp. You are free to utilize only in-member definitions if desired but it is best practice to declare the class in your header file and impliment the methods in a source file. The list class will impliment a variable-sized array where you will perform memory management within the class methods. List class composition: For the purposes of grading, your list class shall contain the private member double* _data which will be the array of floating point values. Your implimentation of list must not include any of the following headers from the C++ STL: vector, array, deque, foward_list, list, stack, queue, or priority_queue. Construction: list must be default constructable. The default constructor shall set list::_data equal to nullptr and the size of the list to 0, i.e., there is no data stored. list must be constructable with a parameterized constructor accepting an unsigned integer parameter (reference as N herein) denoting the intended size of the array. This constructor shall allocate an array of size N and set the size to be N Member functions: . . . . list::Size() shall accept no parameters and return the size of the array as an unsigned int list:: index(double d) shall return the first index of the element matching the input parameter d as type int. If d does not exist in the array the function should return -1. list:: append(double d) shall append, i.e., add another element at the back, d to the existing list and will return void o e.g., starting with 1 = [1 2 3 4], l.append(10) will result in 1 = [1 2 3 4 10] list::clear() shall delete the current underlying array of data and set the size of the list to 0. This will accept no argument and return void list::pop(unsigned int i) shall remove the element at index i and shift the remaining data down. This will also decrease the list's size by one. o e.g., starting with l = [1 2 3 4], l.pop(1) will result in 1 = [1 3 4] list::insert(double d, unsigned int i) shall insert an element into the exisitng list at index i with value d . This will shift the remaining data up and increase the size by one o e.g., starting with 1 = [1 2 3 4], l.insert(10, 1) will result in 1 = [1 10 2 3 4] list:: reverse() shall reverse the order of the list. This will not change the size of the underlying array and will accept no values and return void list::at(unsigned int i) shall return type double with value of the element at index i list::at (double d, unsigned int i) shall assign the existing element i with value d . This will return void . . Useful References Below are listed references that might be useful Class tutorial: http://www.cplusplus.com/doc/tutorial/classes/ Dynamic memory tutorial (C++ new, new[], delete, and delete[] : http://www.cplusplus.com/doc/tutorial/dynamic/ Malloc tutorial: https://www.tutorialspoint.com/c_standard_library/c_function_malloc.htm Dynamic array in C example: http://www.mathcs.emory.edu/-cheung/Courses/255/Syllabus/2-C-adv-data/dyn-array.html Testing Your Program This homework assignment is graded with only unit-tests Unit tests The Project O will be tested against 7 individual test executables. Note this larger number of executables will cause a longer compilation time within the tester (the entire pipeline takes around 2 minutes on my local computer). The following executables will be generated: listTester_CLEAR_TEST: Tests the list::clear() method listTester_REVERSE_TEST: Tests the list: : reverse() method listTester_INSERT_TEST: Tests the list::insert() method listTester_APPEND_TEST: Tests the list:: append() method. Note this method is also used in other tests ist Tester_CONSTRUCTION_TEST: Tests the default and parameterized constructors list Tester_POP_TEST: Tests the list:: pop() method listTester_ACCESS_TEST: Tests the list::at() and list:: index() methods. Note list::at() is also used in other tests . which will test your implimentation against an expected solution generated by the std::vector class. The code for the tester is available on Piazza as normal. Debugging your code You are free (and encouraged to) provide your own debug messages from within your list class implimentation. There will by many of you which experience a segmentation fault (a runtime error difficult to track down) and without compiling the tester locally there is not a good way to perform debugging. Therefore it is encouraged to print informational statements from within your class to assist with future debugging. Note that no output comparison is performed so your program's output is incondequential. You are also encouraged to perform your own testing locally where you may utilize a debugger. Note that arguments to your list class are generated randomly from the tester but you may exercise much of the same function calls from a hard-coded locally-run executable. Please attend an office hour for assistance with this task. Example.cpp The file example.cpp, which is included in your GitLab, is shown below: Dinclude "List.hpp" #include atli) ","; } std::cout at(1 - size) - 1) (15 - 1)); } // Print the initial list print_list(1); std::cout index(val) insert (190.0, 7); // Print the list back out print_list(l): // Reverse the list std::cout reverse(); // Print it back out print_list(1); delete 1: return; } } and should produce output: Creating a list with append [0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Deleting that list ... Making a new list ... [15, 14, 13, 12, 11, 10, 9, 8, 7, 6] Index of element with value 8 is 7 Removing element index 2 [15, 14, 12, 11, 12, 9, 8, 7, 6] Adding 189.0 at index 7 [15, 14, 12, 11, 10, 9, 8, 100, 7, 61 Reversing the list [6, 7, 100, 8, 9, 10, 11, 12, 14, 15] please note that static_cast double(i) is changing the data type of i from unsigned int to double. This is analagous to (double) i that you may have seen in C or just doing i * 1.0. We will discuss this concept further but it is not integral to the list class itself

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