TextLabel Concatenation (operator+ and operator+=)
mediumQuestion 82You are building UI labels that have a prefix and main text.
Create a class TextLabel that stores TWO strings: prefix and text.
Rules:
- getText() should return prefix + text
- When combining labels, you should combine BOTH parts.
Requirements:
1) Constructor TextLabel(string prefix, string text)
2) string getText() const
3) operator+= appends other.prefix to this->prefix AND other.text to this->text
4) operator+ returns a NEW TextLabel using operator+=
Do NOT write a main function.
Expected output
HelloWorld CWJ Rocks
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
ClassesOperator Overloading
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.