Trouble creating a class to manipulate strings

So the goal of the code is to create a class to manipulate words/strings. They're stored as an array of characters

I'm lost as to how to call the strings when adding/concatenating them. What's the proper way?

I've been given this interface file that can't be changed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef WORD_
#define WORD_

using namespace std;
#include <iostream>

class Word
{
  public:

    // Capacity of a Word
    //
    static const unsigned int MAX = 32;

  private:

    unsigned Length;    // Number of characters in Word
    char Mem[MAX];      // Memory to hold characters in Word

  public:

    // Construct empty Word
    //
    Word() { Length = 0; }

    // Reset Word to empty
    //
    void reset() { Length = 0; }

    // Return status information
    //
    bool empty() const { return Length == 0; }
    bool full()  const { return Length == MAX; }

    unsigned length()  const { return Length; }
    unsigned maximum() const { return MAX; }

    // Return reference to element I
    //
    char& operator[]( unsigned I ) { return Mem[I]; }

    // Return constant reference to element I
    //
    const char& operator[]( unsigned I ) const { return Mem[I]; }

    // Construct Word by copying array of characters
    //
    Word( const char [] );

    // Copy Word to the current Word
    //
    Word& operator=( const Word& );

    // Append Word to the current Word
    //
    Word& operator+=( const Word& );
};

// Return Word which is the concatenation of two Words
//
Word operator+( const Word&, const Word& );

// Compare two Words (equality and relational operators)
//
bool operator==( const Word&, const Word& );
bool operator!=( const Word&, const Word& );
bool operator< ( const Word&, const Word& );
bool operator<=( const Word&, const Word& );
bool operator> ( const Word&, const Word& );
bool operator>=( const Word&, const Word& );

// Insert Word into stream
//
ostream& operator<<( ostream&, const Word& );

// Extract Word from stream
//
istream& operator>>( istream&, Word& );

#endif 




Here are the function definitions that I've tried to write:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*-----------------------------------------------------
	Name: copy constructor for class "Word"

	Purpose: Initialize the letters inside a Word object
	Return:  The boolean value "true" if word is empty
-----------------------------------------------------*/

Word::Word( const char Existing[])
{
  Mem[Length] = Existing[Length];
}





/*-----------------------------------------------------
  Name: Assignment operator for class "Word"

  Purpose: Copy the contents of one word into another
  Receive: The word which is to be copied
  Return: The word
  ---------------------------------------------------*/
  
Word& Word::operator=( const Word& Existing)
{
  Length = Existing.Length;
  Mem[MAX] = Existing.Mem[MAX];
}





/*-----------------------------------------------------
  Name: operator+=

  Purpose: Append a word to the current word
  Receive: A word
  Return:  Concatenation
-----------------------------------------------------*/
Word& Word::operator+=( const Word& Existing)
{
  Length = Length + Existing.Length;

  char ExistingTemp = Existing.Mem[Length];

  char Temp[Length];
  
  //Temp = Mem + ExistingTemp;

  return Existing.Mem[Length];
  
}



/*-----------------------------------------------------
  Name: operator+

  Purpose: Concatenate 2 words together
  Receive: 2 words
  Return:  Concatenation of the 2 words
-----------------------------------------------------*/
Word operator+(const Word& One, const Word& Two)
{
  Word.Mem[Length] = One.Mem[Length] + Two.Mem[Length]; 

  return Word;
}




I've tried defining the basic functions, but I'm totally confused. I've been trying to work on this with some other people, but they're just as lost as I am.
We just don't know how to call the actual strings when we want to add/concatenate them.

Any help would be great
Go MSU! this project has me bent over lol
Topic archived. No new replies allowed.