SWEN-250 Activity: Implementing a SimpleString Class

Objective

In this activity, you will implement your own version of a string class in C++. This exercise is designed to give you hands-on experience with:

Background

In Java and Python, strings are managed objects that handle memory automatically. In C++, while we have std::string, it's important to understand how strings could be implemented behind the scenes — especially in a language where you are responsible for memory management.

This assignment will introduce you to the Rule of Three, which states that if your class allocates dynamic memory, you must explicitly define:

Your Task

You will implement a class called SimpleString that holds a dynamically allocated null-terminated C-style string (i.e., a char*).

You will:

Files Provided - Download Here

Your Implementation Must Include

class SimpleString {
public:
    SimpleString();                          // Default constructor
    SimpleString(const char* text);          // Construct from a C-string
    SimpleString(const SimpleString& other); // Copy constructor
    SimpleString& operator=(const SimpleString& other); // Copy assignment
    bool operator==(const SimpleString& other) const;   // Equality
    ~SimpleString();                         // Destructor

    int Length() const;                      // Get string length

    friend std::ostream& operator<<(std::ostream& os, const SimpleString& str); // Stream output

private:
    char* data;
};

Testing

You will test your implementation using the provided main.cpp. This file uses a custom Check() function to provide [PASS]/[FAIL] results for:

You are encouraged to add your own additional tests as needed!

Rules and Requirements

Submission

Submit via Gitlab in a directory called SimpleString

Ensure your submission compiles and runs cleanly with no memory leaks.