Outputting Randomized Arrays

For an assignment I am having a user enter the name of a file that contains "Song Data" the file is set up like this:

(example)

1012 C
3333 R
90 E

And so forth for 15 lines. The first value represents the song Id and the second is a character C, D, E, or R that represents the type of song. After the file is opened I have two parallel arrays that are read from the file:

1. int songId[15]
2. char typeOfSong[15]

I am able to read the entire file, which symbolizes playing the playlist in order, but now I have to play a randomized playlist.

It has been given to us that we need to set up two parallel arrays, that are also parallel to the first two (songId and typeOfSong). These must also be one dimensional. The first array will will be indexes into the songId array telling is what order to put the songs in and the second is an array of true/false values telling us if the song has already been chosen or not.

I am completely lost on how to set this up. If anyone could lead me in the right direction that would be great!

I have that:

1
2
3
4
5
6
7
8
9
10
11
12
void playRandomPlaylist (int songId[], char typeOfSong[])
{ 
    
    // the size of the file and therefore arrays is known
    rand() % songId[15]
    
    // choosen and notChoosen symbolizing true and false values
    typedef enum {choosen, notChoosen};
}



I don't know what 'chosen' and 'not chosen' mean. But you can use the function std::random_shuffle to randomize array:
http://www.cplusplus.com/reference/algorithm/random_shuffle/

#include the file <algorithm>
to shuffle an array 'arr' of size 'n' call the function from your code like this:
std::random_shuffle(arr,arr+n);
Topic archived. No new replies allowed.