Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with making hierarchy chart showing the logical components of this program here is the code below: #include #include #define MAX 100 using

I need help with making hierarchy chart showing the logical components of this program here is the code below: #include #include #define MAX 100 using namespace std; // Song class class Song { private: string title; string artist; string genre; float length; public: Song() {} Song(string t, string a, string g, float l) { title = t; artist = a; genre = g; length = l; } // displays the song void display() { cout << " Title: \t" << title << " "; cout << " Artist:\t" << artist << " "; cout << " Genre: \t" << genre << " "; cout << " Length:\t" << length << " "; } float getLength() { return length; } }; // Playlist class class Playlist { private: string name; int totalSongs; Song songs[MAX]; public: Playlist() {} Playlist(string n) { name = n; totalSongs = 0; } // adds song to the playlist void addSong(Song song) { if (totalSongs < MAX) { songs[totalSongs] = song; totalSongs++; cout << "Song added successfully" << endl; } else { cout << "Playlist Full!" << endl; } } // displays the playlist void display() { cout << "Name of the playlist: " << name << endl; if (totalSongs == 0) cout << "Playlist is empty!" << endl; else { for (int i = 0; i < totalSongs; i++) { cout << i + 1 << ".-------------------------------------- "; songs[i].display(); } cout << "The playlist of name " << name << " has a total length of " << getTotalLength() << endl; } } // returns total length float getTotalLength() { float length = 0; for (int i = 0; i < totalSongs; i++) { length += songs[i].getLength(); } return length; } }; // reads the song data and returns the song object Song getSong() { string title, artist, genre; float length; fflush(stdin); cout << "Insert the title of the song: "; getline(cin, title); cout << "Insert the artist name of the song: "; getline(cin, artist); cout << "Insert the genre of the song: "; getline(cin, genre); cout << "Insert the length of the song: "; cin >> length; // create song object and return it Song song(title, artist, genre, length); return song; } // displays the menu and returns the menu choice int menu() { int menuChoice; cout << " 1. Create New Playlist" << endl; cout << "2. Dispay all Playlists" << endl; cout << "3. Exit" << endl; cout << "Enter your choice [1-3]: "; cin >> menuChoice; return menuChoice; } int main() { //Declare variables /* Name, title, artist, and genre are of type string. length is type float. */ string name; int menuChoice; int count = 0; char choice; Playlist playList[MAX]; // print header cout << "############################################################ "; cout << " DJ Playlist Manager "; cout << "############################################################ "; // continue displaying menu options, until user quits while (true) { // get menu choice menuChoice = menu(); // Add playlist if (menuChoice == 1) { fflush(stdin); cout << "Insert a name for this playlist: "; getline(cin, name); Playlist newPlayList(name); // keep asking for songs to add into the playlist while (true) { cout << "Do you want to add songs? (y/n): "; cin >> choice; if (choice == 'y' || choice == 'Y') { newPlayList.addSong(getSong()); } else break; } playList[count] = newPlayList; count++; } // display all playlist else if (menuChoice == 2) { if (count == 0) { cout << "No Playlist Found!" << endl; } else { for (int i = 0; i < count; i++) { playList[i].display(); } } } else if (menuChoice == 3) { break; } else { cout << "Invalid Choice! Try Again!" << endl; } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago