Queue

17.3 - Queue basic 3


Your task is now to create a mixtape song queue simulation program. Your program should accept those commands:

  • enqueue
    Enqueue the song to the end of the song queue. It should create a new Song object and push it into the stack. It should also print "Added [song name] to the song queue." Note that the song name will always be one word only.

  • wait
    Wait for duration amount. If any song ends during this period it should print out "Finished listening to [song name]." Multiple songs can end during a single wait command. Note that if there is still a song in the queue, the wait duration should be kept for the next wait (e.g. waiting for 10 and 20 should end a song with 30 duration.)

Sample input

enqueue LofiHipHopToRelaxAndStudy 30
wait 10
wait 25
enqueue Duwang 15
wait 10
enqueue JPop 5
wait 5
enqueue AllStar 10
enqueue KingCrimson 20
wait 30

Sample output

Added LofiHipHopToRelaxAndStudy to the song queue.
Finished listening to LofiHipHopToRelaxAndStudy.
Added Duwang to the song queue.
Added JPop to the song queue.
Finished listening to Duwang.
Added AllStar to the song queue.
Added KingCrimson to the song queue.
Finished listening to JPop.
Finished listening to AllStar.
#include <queue> #include <iostream> struct Song { std::string name; int length; }; int main() { }