Hey everyone. :) I'm working on a lab for school and I am a bit confused. Just to warn you, I am a complete noob to programming, so this thread is probably filled with noobish questions. Ok so here's the lab:

Refer to the MyString Class files for the .h and .cpp files add the following member functions to the class:

int getStrLen() const; return the current length of a MyString object

void strCat(const MyString &s); concatenate MyString object s to the end of the current MyString object

int strCmp(const MyString &s) const; compares the s MyString object to the current MyString object and returns:
0 if current MyString object == s
int <0 if current MyString object < s
int >0 if current MyString object > s

MyString operator +(const MyString &s)const; returns the concatenation of the s MyString object to the current MyString object


Write a driver main function to test the new member functions you have added to the MyString Class.


The functions he has listed for me to add to the classes are all built-in functions in the string library, so why would we have to add code for it in the header and cpp files in the MyString class?

Plus I don't understand the operator overload he has listed and the explanation for what it does next to it. Why would that return the concatenation of the s MyString object to the current MyString object?

Here are the header and cpp files for the MyString Class I am supposed to modify:

Header File:
Code:
#ifndef myString_h
#define myString_h

#include <iostream>

using namespace std;

class MyString
{
private:

	char *str;

	int  len;

	static int numStrs;

public:
	MyString();
	MyString(const char *s);
	MyString(const MyString &s, int n);

	~MyString();

	MyString(const MyString &st);

	MyString &operator =(const MyString &st);

	friend ostream & operator <<(ostream &outs, const MyString &st);
};


#endif
Source File (cpp):
Code:
#include <iostream>
#include <cstring>

#include "myString.h"

using namespace std;

int MyString::numStrs = 0;

MyString::MyString()
{
	len = 0;

	str = new char[1];

	str[0] = '\0';

	cout << "\nString #" << ++numStrs << ";\""
		 << str << "\" default string created.\n";
}

MyString::MyString(const char *s)
{
	len = strlen(s);
	str = new char[len+1];

	strcpy(str, s);

	cout << "\nString #" << ++numStrs << ";\""
		 << str << "\" string created from user string.\n";

}

MyString::MyString(const MyString &s, int n)
{
	len = strlen(s.str);


	if(n <= len)
		len = n;
	else
		len--;

	str = new char[len + 1];

	strncpy(str, s.str, len);
	str[len] = '\0';


	cout << "\nstring #" << ++numStrs << ": \""
		 << str << "\" string created from substring.\n\n";
}

MyString::~MyString()
{
	numStrs--;
	cout << "\n\"" << str << "\" object deleted;"
		 << numStrs << " strings left.\n";

	delete [] str;
}

MyString::MyString(const MyString &st)
{
	numStrs++;
	len = st.len;
	str = new char[len + 1];
	strcpy(str, st.str);

	cout << "\nstring #" << numStrs << ": \""
		 << str << "\" created in copy constructor\n\n";
}

MyString &MyString::operator =(const MyString &st)
{
	if (this == &st)
		return *this;
	else
	{
		delete []str;
		len = st.len;
		str = new char[len + 1];
		strcpy(str, st.str);
		return *this;
	}
}

ostream & operator <<(ostream &outs, const MyString &st)
{
	outs << st.str;
	return outs;
}
I don't want anyone to do the lab for me. I just want help in understanding what my teacher wants me to do. I thank anyone who can help me. :)