I am having trouble writing the length function for the program...the one from above, here is what i have so far:
int A4String::length() const
int count = 0;
while(data[count] != '\0')
A4String is the string class and this function is supposed to count the number of characters in the object .
char * data is one of the variables given in the private section of the class.
Here is the assignmment:
An A4String class should provide the ability to store a variable length character array. You will
achieve this by using a dynamically resizing char array. The A4String will be fairly restricted in
its functionality, when compared to the STL string class. But, we will be able to alter the size of
an existing array to accommodate more characters. Your A4String should start with enough
space to store 5 characters including the ‘\0’. If more space is required, you should double the
size. Rest assured that we will be adding more functionality in a later assignment.
int capacity - the number of characters allocated in the object.
char *data - a character pointer that points to an array of characters that is
terminated with a ‘\0’.
A4String( const A4String & )
A4String( const char * )
A4String& operator = ( const A4String & )
Overloaded assignment operator
bool operator == ( const A4String & ) const
Overloaded equivalence operator
int length( ) const
Return the length of the A4String
Returns a string representation of an A4String