Sure, here's the `strip` function that removes C++ comments from the input:
```python
def strip(commented_input):
"""
Removes C++ comments from input and returns the uncommented portion of the program.
Works with both single-line (//) and multi-line (/* */) comments.
"""
uncommented_output = ''
i = 0
in_comment = False
while i < len(commented_input):
if not in_comment and commented_input[i:i+2] == '//':
# Single-line comment found, skip to end of line
eol = commented_input.find('\\', i)
i = eol if eol != -1 else len(commented_input)
elif not in_comment and commented_input[i:i+2] == '/*':
# Multi-line comment start found, skip to end of comment
in_comment = True
i += 2
elif in_comment and commented_input[i:i+2] == '*/':
# Multi-line comment end found, continue with input after comment
in_comment = False
i += 2
elif not in_comment:
# Not in a comment, add current character to output
uncommented_output += commented_input[i]
i += 1
else:
# In a comment, skip current character
i += 1
return uncommented_output
```