V CISC 3142 — Lab #8

CISC 3142
Programming Paradigms in C++
Lab #8
A String Class and the Canonical Form

How to Develop and Submit your Labs

Lab 8 — A String Class (Optional)

Create a String class, which — while having minimal functionality — illustrates the use of and need for the canonical form.

Overview

Here is the .h file for the class (note the use of the mystring namespace again):
#ifndef MYSTRING_H
#define MYSTRING_H

#include <iostream>

namespace mystring {

class string {
	friend std::ostream &operator <<(std::ostream &os, const string &s);
	friend string operator +(const string &s1, const string &s2);
public:
	string(const char *cs="");
	string(const string &s);
	~string();
	string &operator =(const string &rhs);
	char &operator [](int index);
	string &operator +=(const string &s);
	int length() const;
	void clear();
private:
	char *cs;
};

}

#endif
I've also supplied a string_Exception class and an app for testing your class (it is also the test driver in Codelab). Finally, I captured the expected output — you can see it in mystring_app.stdout.

Implementation Notes

Code Provided for this Lab