Modify has hired you to create a program that shuffles playlists[2]. Try your program with your own playlist that has some of your favorite songs. Add the titles of your favorite songs in a text file playlist.txt (one song per line and up to 5000 songs). Write a program that creates a different shuffled playlist of playlist.txt. Create seven different shuffled playlists of playlist.txt (one for each day of the week) and save these playlists in a text file named shuffle[DayOfWeek].txt (one song per line), where [DayOfWeek] is Monday to Sunday.

To solve that problem do the following:

  • Read and store the song titles in a dynamic string array playlist the i-th song is in the (i-1)-th position. Assume you have n (<=5000) songs.
  • Implement a function that does the shuffling of favorites. This function should be based on the modern version of the Knuth/Fisher-Yates algorithm for shuffling [1].

The algorithm looks like that:

To shuffle an array a of n elements (indices 0..n-1):
for i from n-1 downto 1 do
j is a random integer within 0 = j < i
swap(a[j],a[i])

The generated random numbers are really pseudo-random numbers. To create random numbers in C you have to set initially the seed of the random number generator only once (srand(time(0))) and include the appropriate library time.h. The rand() function can be used afterwards as many times as needed and returns a random integer x that is greater than or equal to 0 and less than RAND_MAX. Use the x%k operation to get a number greater or equal to 0 and less than k.

  • Traverse favorites, and write them in the text file shuffleMonday.txt (one song per line).
  • Repeat steps a-c, six more times for the rest of the week days.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.