I'm working on an assignment and am very new to a lot of the concepts it wants me to do.
I have not finished the code yet. As of now I simply want to see if my code looks correct and I have some questions about the assignment itself. Below is my assignment is below that is my current code.
I haven't yet gotten to member function 1, so you don't have to read there and beyond yet. All I've done is added the names to the header.
~~~
Instructions: In this lab you will create a class for a Dynamic Array of Strings. This class may be useful for future projects. The class will provide the following functionality:
Get a string from the array
Add a string to the front or back of the array
Delete a string from the front or back of the array
Get the number of strings in the array
Get the maximum capacity of the array
Clear the array
Sort the array
Get the array as a comma separated list
Ability to grow on demand
For Extra Credit you can add the following:
Save the array to a file
Retrieve a previous saved array from a file
Class –DynamicStringArray:
Contains a dynamic array of dynamic strings.
Private Data Members:
A dynamic array of dynamic strings, i.e. a dynamic array of string*s.
An integer to hold the maximum capacity of your array.
An integer to hold the current size of your array.
Default Constructor:
Initializes the array to 10 elements and initializes the elements to NULL.
Overloaded Constructor:
Initializes the array via an unsigned integer parameter. If the parameter's valueis not valid (i.e. 0) set the array to a capacity of 10. Initializes all elements to NULL.
Destructor:
Frees the memory for all strings
Frees the memory for the dynamic string* array
Member Function 1:
Named At. Has one parameter, anunsigned integer that corresponds to a location in the array. If that location doesn't exist in the array throw the string "Invalid Location". If the location does exist return a pointer to the string.
Member Function 2:
Named GetFirst. Returns a pointer to the first string in the array. If the array is empty throw the string "Array Empty".
Member Function 3:
Named GetLast. Returns a pointer to the first string in the array. If the array is empty throw
the string "Array Empty".
Member Function 4:
Named AddFront. Has one parameter, a dynamic string. Adds this string to the beginning of the array. Note: this requires you to shift all the elements in the array. If the array is full increase the capacity of the array (call the IncreaseCapacityfunction) and then add the dynamic string.
Member Function 5:
Named AddBack. Has one parameter, a dynamic string. Adds this string to the end of the array. If the array is full increase the capacity of the array (call the IncreaseCapacityfunction) and then add the dynamic string.
Member Function 6:
Named DeleteFront. Deletes the first element in the array. Note: this requires you to shift all the elements in the array. If the array is empty throw the string "Array Empty".
Member Function 7:
Named DeleteBack. Deletes the last element in the array. If the array is empty throw the string "Array Empty".
Member Function 8:
Named GetSize. Returns an unsigned integer that is the current size of the array. This is a const function.
Member Function 9:
Named GetCapacity. Returns an unsigned integer that is the current maximum capacity of the array. This is a const function.
Member Function 10:
Named Empty. Returns a Boolean. True if the array's size is 0. This is a const function.
Member Function 11:
Named Clear. Deletes all of the dynamic strings in the array and sets the size of the array to 0.
Member Function 12:
Named Sort. Sorts the array A-Z. You must use the private function ToUpper as this helps when comparing strings of mixed case.
Member Function 13:
Named ToString. Returns a string containing all of the strings in
the array, comma separated.
Overloaded Friend operator<<:
Outputs a comma separated list of all of the strings in the array.
Private Member Function 1:
Named IncreaseCapacity. Increases the capacity of the array by 10. Note: this requires you making a second dynamic array and "copying" over the original data.
Private Member Function 2:
Named ToUpper. Takes a string as a parameter and returns that
same string with all the characters uppercased.
~~~
Code:#include "dynamic_string_array.h" #include <iostream> #include <cmath> #include <string> #include <cctype> #include <sstream> using std::cin; using std::cout; using std::endl; using std::string; using std::stringstream; DynamicStringArray::DynamicStringArray() { int *myarray[10] = {}; } DynamicStringArray::DynamicStringArray(int arraymax = 10) { arraymax_ = arraymax; int *myarray[arraymax] = {}; } DynamicStringArray::~DynamicStringArray() { delete[] arraysize_; }~~~Code:#ifndef DYNAMIC_STRING_ARRAY_H #define DYNAMIC_STRING_ARRAY_H #include <string> #include <climits> class DynamicStringArray { private: int arraymax_; int arraysize_; IncreaseCapacity(); ToUpper(); public: DynamicStringArray(); At(unsigned int Loc); GetFirst(); GetLast(); AddFront(string *str); AddBack(string *str); DeleteFront(); DeleteBack(); GetSize(); GetCapacity(); Empty(); Clear(); Sort(); ToString(); } #endif /* DYNAMIC_STRING_ARRAY_H */
Questsions:
1) As of now does my code look correct? I want to make sure I at least have the basics done before moving on to the rest of it.
2) What does the assignment mean when it says "return a pointer"?