Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answers in C++ You are to implement a class that stores a list of strings* and, in part 2, write functions that use objects of

Answers in C++

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

You are to implement a class that stores a list of strings* and, in part 2, write functions that use objects of your class. The class should use a dynamic array as its underlying representation. Please read the requirements carefully, paying particular attention to the names and input and output requirements of the class and its methods. We will be testing your class in our test program, if you do not follow the requirements our test program will not compile and your assignment will not be marked. Please read the General Requirements before starting your assignment. *That is objects of the standard string class - so you will need to include . Do not use C strings! Lists A list is an abstract data type that preserves the order of its contents. For example if you enter the strings milk, butter, eggs into a list in that order then the list will contain milk at its first position, butter in its second and eggs in its third. Lists allow elements to be inserted at any position and removed from any position. *They are not sorted, it is just that the order of its contents is preserved. Part 1 - StringList Class Methods 1. default constructor - creates an array of strings of size 4 in dynamic memory and assigns its address to the class' string pointer, sets maximum size to 4, and current size to 0. 2. copy constructor - creates a deep copy of its constant StringList reference parameter. 3. destructor - deallocates dynamic memory associated with the object's string (array) pointer. 4. overloaded assignment operator - deep copies its constant StringList reference parameter to the calling object; deallocates dynamic memory associated with the calling object's original array; returns a reference to the calling object; should behave correctly during self-assignment. 5.insert - inserts its string parameter (the first parameter) at the index specified by its integer parameter (the second parameter). Before insertion all array element at or above the insertion point are moved up one position in the array (to make space for the inserted value). If the underlying array is full before the insertion it first doubles the maximum size attribute, creates an array of twice the size of the current array, copies the contents of the old array to the new array, frees memory associated with the old array, and assigns new array's address to object's array pointer, then inserts the string and increments current size. If the index parameter is less than 0 or greater than the current size the method should throw an out_of_range exception. 6. remove - returns the string stored at the index given by its integer parameter. Moves down all array elements above the index by one position in the array (thereby overwriting the removed value) and decrements current size. If the index parameter is less than 0 or greater than current size-1 the method should throw an out_of_range exception. 7. swap - swaps the two array elements stored at the indexes given by its two integer parameters. If either index parameter is less than 0 or greater than current size-1 the method should throw an out_of_range exception. 8. retrieve- returns the string stored at the index given by its integer parameter. If the index parameter is less than 0 or greater than current size-1 the method should throw an out_of_range exception. 9. size - returns an integer equal to the number of values in the calling object. 10. concatenate - returns a StringList object that contains the contents of the calling object followed by the contents of its constant StringList reference parameter; the size of the returned object's underlying array should be the greater of 4 and the number of values stored in it. Attributes Your class should be implemented with a dynamic array and should have the following private member variables A pointer to a string that will be used to point to an array of strings in dynamic memory An int that records the current size of the array (the number of values stored in the array) An int that records the maximum size of the array Notes The calling object should be made constant (const) for any method where the calling object's attribute values should not change Method parameters and return values are noted in the method descriptions - you must not add additional parameters to the methods; if the method description does not mention a parameter it does not have one, similarly if no return value is mentioned the method is void (or a constructor or destructor). Methods must be given the same names as shown above. Files Your class should consist of a header file called StringList.h that contains the class definition and an implementation file called StringList.cpp that contains the method definitions. Libraries The only libraries that should be included are and . You may also include is you wish, if so it should be in the .cpp file. String Objects Your array should contain string objects. You can find information about the standard string class here. The main things you need to know about strings for this assignment are: You can assign an existing string variable or a string literal to a string variable . e.g. string str 1 = "bob"; or str 1 = str2; (where str1 and str2 are strings) . You can use the normal comparison operators to compare strings - you do not have to compare them character by character o e.g. if (str1

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

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago