#include #include using namespace std; #include "tvector.h" #include "randgen.h" struct Track { string title; // title of song/track int number; // the original track number }; void SwapTracks (Track & track1, Track & track2) { Track temp; temp = track1; // swap entries track1 = track2; track2 = temp; } void Print(const tvector& tracks, int count) // precondition: there are count locations in tracks // postcondition: contents of tracks printed { int k; for (k=0; k < count; k++) { cout << tracks[k].number << "\t" << tracks[k].title << endl; } } void Shuffle(tvector & tracks,int count) // precondition: count = # of entries in tracks // postcondition: entries in tracks have been randomly shuffled { RandGen gen; // for random # generator int randTrack; int k; // choose a random song from [0..count-1] for all songs for(k=0; k < count; k++) { randTrack = gen.RandInt(0, count-1); // random track SwapTracks (tracks[randTrack], tracks[k]); // swap entries } } int main() { int i; tvector tracks(10); tracks[0].title = "Yaz"; tracks[1].title = "Farkindayim"; tracks[2].title = "Asktan Ne Haber"; tracks[3].title = "Su Saniye"; tracks[4].title = "Arka Sokaklar"; tracks[5].title = "Karsi Pencere"; tracks[6].title = "Oyalanma"; tracks[7].title = "Adi Bende Sakli"; tracks[8].title = "Tutuklu"; tracks[9].title = "Dus Bahceleri"; for (i=0; i < 10; i++) tracks[i].number = i + 1; Print(tracks, 10); Shuffle(tracks, 10); cout << endl << "---- after shuffling ----" << endl << endl; Print(tracks, 10); return 0; }