CJCoding With Joseph
15free / daySign inCreate account

Playlist Assignment That Survives p = p

Write a class Playlist that owns a heap array of track lengths in seconds, with a copy assignment operator that is safe when an object is assigned to itself.

Private members:
- int* lengths;
- int count;

Public interface used by the hidden driver:
``
Playlist(int n);                              // new int[n], every slot 0
~Playlist();
Playlist& operator=(const Playlist& other);   // deep copy, self-assignment safe
void setTrack(int index, int seconds);
int trackAt(int index) const;
int size() const;
`

The driver does a = a through a reference, then assigns a into a playlist that was built with a DIFFERENT size.

For the input:
`
3
210 185 240
``

the exact output is what is shown in Expected Output.

Free the memory you allocate — this question checks for memory leaks.

Do NOT write a main function.

Expected Output:

size=3
first=210
last=240
independent=1

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
3\n210 185 240\n
This input is automatically fed to your program's stdin
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.