The Song List

Time for another project! This checkpoint puts the vectors and loops from the last two lessons to work, together with everything you learned before them. As in the first checkpoint, the instructions say what the program should print, and how you write it is up to you. And as there, each exercise also runs your program with other data, so it has to work everything out from the vectors.

The project. You've made a playlist for your bus ride to school. Over three exercises, your program will list the songs with their lengths, find the longest one, and work out which songs you'll hear to the end before you get off the bus.

The data. The vector songs holds the names of the songs, and the vector lengths holds how long each of them plays, in seconds. Elements with the same index belong together, like the items and prices in the last exercise on loops: songs[0] is "Pixel Heart", and lengths[0] is the length of that song, 214 seconds. The vectors are written one element per line to make them easier to read. C++ doesn't mind: the statement goes on until the semicolon after the closing brace. The comma after the last element is allowed too, and it makes adding another element easier.

The task. Print the playlist, each song with its number and its length in minutes and seconds, and below it, how long the whole playlist plays. 214 seconds is 3 minutes and 34 seconds, which is written 3:34. For this playlist, the program prints:

1. Pixel Heart (3:34)
2. Rainy Tuesday (4:05)
3. Dancing Robots (5:12)
4. Moon Bike (3:07)
5. Midnight Pizza (4:20)
6. Paper Rocket (3:18)
Total: 23:36

Write the seconds with two digits, as clocks do: 245 seconds is 4:05, not 4:5. A tip: when the seconds are less than 10, print a 0 before them.

Get the number of songs from the vector, don't write 6 into your code: when you add a song to the playlist, the program has to list it too. The exercise does that, so try it yourself when your program works. And print the total only once, after the loop has gone through the whole playlist.

Instructions

Print the playlist: each song on its own line, with its number, its name and its length, as in the example.

Below the list, print how long the whole playlist plays.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/3