/******************************************************************** Author: Dana Vrajitoru, IUSB, CS Class: B424 B524 Parallel Programming File name: songs.cc Last updated: November 2020 Description: A program that generates an ideal playlist. Functions generating a random song list. *********************************************************************/ #include #include #include #include using namespace std; #include "songs.h" //#include // Taken from various popular songs. A song title is composed of a random // prep, followed by a verb, preposition, and noun. // Example: "Don't Hold For My Bishop" const int nr_verbs = 15, nr_nouns = 30, nr_prep = 5, nr_starter = 5, word_max_length = 15; char starter[nr_prep][word_max_length] = {"Don't", "I", "You", "You Should", ""}; char verbs[nr_verbs][word_max_length] = {"Stay", "Hold", "Menace", "Trick", "Water", "Scare", "Slide", "Bet", "Catch", "Bleed", "Smoke", "Enjoy", "Think", "Feel", "Wait"}; char prep[nr_prep][word_max_length] = {"The", "That", "Around The", "For That", "For My"}; char nouns[nr_nouns][word_max_length] = {"Frosty", "Midnight", "Tea", "Mistakes", "Heaven", "Gate", "Countdown", "Champion", "Sunshine", "Riptide", "Menace", "Bishop"," Knife", "Trick", "Order", "Water", "Buffaloes", "Clubs", "Heart", "Town", "Bet", "Ship", "Gold Standard", "Coffee", "Dollar", "Nose", "West Coast", "Smoker", "Trouble", "Visitor"}; // Creates a random song with title and attributes void random_song(Song &theSong) { theSong.title1 = rand() % nr_starter; theSong.title2 = rand() % nr_verbs; theSong.title3 = rand() % nr_prep; theSong.title4 = rand() % nr_nouns; theSong.att1 = random_attribute(); theSong.att2 = random_attribute(); } // Returns a real number between 0 and 1 float random_attribute() { return float(rand()) / RAND_MAX; } // Generates n songs titles and their attributes. void generate_songs(Song *songs, int n) { for (int i = 0; i < n; i++) random_song(songs[i]); } // Computes the distance between the songs at the two indexes based on // the arrays of attributes. float distance_song(Song &song1, Song &song2) { return sqrt((song1.att1 - song2.att1)*(song1.att1 - song2.att1) + (song1.att2 - song2.att2)*(song1.att2 - song2.att2)); } // writes out the title of the song on a line void output_song(Song &theSong) { cout << starter[theSong.title1] << ' ' << verbs[theSong.title2] << ' ' << prep[theSong.title3] << ' ' << nouns[theSong.title4] << " (" << theSong.att1 << ", " << theSong.att2 << ")" << endl; }