I need to implement the functions from the header file (2nd piece of code), using a string class (1st piece of code). I'm a little lost on how to start. The 3rd piece of code is my attempt so far. Any direction would be appreciated.
//HEADER FILE
#ifndef STRING1030_H
#define STRING1030_H
#include<iostream>
using std::ostream;
using std::istream;
using std::endl;
using std::cerr;
class String1030
{
public:
// The constructor. The "0" is the digit 0 NOT a
// character. It is used to let us know that
// nothing is being passed to the constructor.
String1030(constchar *buf=0);
//This next is a "copy" constructor. Remember that
//we have to create new storage and then copy
//the array content. We must not just copy the pointer.
String1030(const String1030& oldstring);
// The destructor because we are allocating memory.
// We must deallocate it when the object goes out of
// scope (is destroyed).
~String1030();
String1030& operator=(const String1030& right);
// Allows to change the element at a certain index.
char& operator[](int index);
int getSize(void);
void setSize(int newsize);
constchar *getString();
// Replace the existing string with a new one.
void setString(constchar *carray);
private:
char *buffer;
int mysize;
};
#endif
In particular, notice how implementing a declared member function is done. Those implementations are what needs to go in your implementation file, one for each member function/constructor/destructor.
If you need any more help, let us know. :)
-Albatross
P.S. - You're underthinking your setSize function and overthinking your getSize function.
So my functions in the implementation file will start like this: int String1030::getSize(){} ? As for the overthinking...is there a way I can get the length without a loop? I'm not allowed to use the STL string class.