Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

** Any program that do not compile will receive a zero ** ** Any program that attempts to use std library Vectors will receive a

**Any program that do not compile will receive a zero**  **Any program that attempts to use std library Vectors will receive a zero**  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 s4o it is important that it is tested thouroughly. **The following provides the expected behavior of the private data members and the public interface/API:**  *private:*  **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 **void swap(unsigned pos1, unsigned pos2)** - swap the string in position1 (pos1) of the array with the string in position2, throw an exception if either position is out of bounds **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 **void sort()** - use the bubble sort function discussed in lab to sort the vector like a dictionary (lower letters and less letters first) 

Header file:

#ifndef CMPE126S18_LABS_STRINGVECTOR_H #define CMPE126S18_LABS_STRINGVECTOR_H #include  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(); }; 

the stringVector.cpp

#include "../inc/stringVector.h" #include  stringVector::stringVector() { data=nullptr; length=0; allocated_length=0; } stringVector::~stringVector() { delete[]data; } unsigned stringVector::size() { return length; //return ; } unsigned stringVector::capacity() { return allocated_length; //return ; } void stringVector::reserve(unsigned new_size) { } bool stringVector::empty() { } void stringVector::append(std::string new_data) { } void stringVector::swap(unsigned pos1, unsigned pos2) { } stringVector &stringVector::operator=(stringVector const &rhs) { } //return ; } std::string &stringVector::operator[](unsigned position) { } //return ; void stringVector::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

More Books

Students also viewed these Databases questions