Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this lab you will be creating a auto-expanding dynamic-array. This array will explicitly hold std library strings. As with all labs you can create

For this lab you will be creating a auto-expanding dynamic-array. This array will explicitly hold std library strings. As with all labs you can create any PRIVATE data members/ methods you want, but the Public interface should remain the same. While tests will be provided, you will need to add your own test cases to ensure all corner cases are accounted for and avoided. This class will be used for future labs so it is important that it is tested thouroughly. The following provides the expected behavior of the private data members and the public interface/API: std::string * data - pointer to the string data unsigned length - Current number of strings stored in array unsigned allocated_length - Current number of strings allocated to be held in the array public: stringVector() - Constructor, should construct an empty object virtual ~stringVector()- Destructor, should deallocate all memory used by object (NO MEMORY LEAKS) unsigned size()-return the number of strings stored in array unsigned capacity() -return number of strings currently allocated to be stored in array void reserve() - Allows user to choose the allocation size, if it is small than current array then data should be truncated to fit bool empty() - returns true IFF the array is empty void append(std::string data) - append data to end of array, double array capacity if this is over capacity stringVector &operator = (stringVector &rhs) - Copies RHS to object calling the function (this should be a hard COPY, creating a separate object with same values) std::string& operator[](unsigned position) -return a reference to the string at this position, throw an exception if out of bounds sort() - use the bubble sort function discussed in lab to sort the vector like a dictionary (lower letters and less letters first) 
class stringVector { private: std::string * data; unsigned length; unsigned allocated_length; public: stringVector(); virtual ~stringVector(); unsigned size(); unsigned capacity(); void reserve(unsigned new_size); bool empty(); void append(std::string new_data); void swap(unsigned pos1, unsigned pos2); stringVector &operator = (stringVector const &rhs); std::string& operator[](unsigned position); void sort(); 

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 Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

BD 1 2 . .

Answered: 1 week ago