← Back to Pointers
Question 699
Playlist Assignment That Survives p = p
Playlist Assignment That Survives p = p
Write a classPlaylistthat 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 doesa = athrough a reference, then assignsainto 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
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.