← Back to Classes
Question 82
TextLabel Concatenation (operator+ and operator+=)
TextLabel Concatenation (operator+ and operator+=)
You 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) stringgetText()const 3) operator+= appendsother.prefixtothis->prefixANDother.texttothis->text4) 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 — 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.