Playlist Assignment That Survives p = p
mediumQuestion 699Write 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 240the 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
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.