Question: i need a visual flow chart for this program. // week 7 Final DJ Program.cpp : Defines the entry point for the console application. //

i need a visual flow chart for this program.

// week 7 Final DJ Program.cpp : Defines the entry point for the console application.

//

//4/14/18

#include "stdafx.h"

#include

#include

#include

#include

#include

#include

#include

using namespace std;

struct Song {

string artistName;

string songTitle;

string songGenre;

double songLength;

Song(const string s_title, const string n_artist, const string s_genre, const double s_length)

: songTitle(s_title), artistName(n_artist), songLength(s_length), songGenre(s_genre) {}

};

struct Playlist

{

std::string name;

double length;

std::vector songList;

Playlist(const string title) :name(title) {}

void addSong(Song song) {

songList.push_back(song);

length += song.songLength;

}

};

Playlist& addSongs(Playlist& play);

std::vector& addNewPlaylist(std::vector& play);

void displayPlaylist(Playlist list);

void displayAllPlaylists(const std::vector& plays);

int exitMenuChoice();

void waitForEnter();

void saveonFile(const std::vector& plays);

// Main Menu

int main()

{

vector toPlay; // at least 1 default element

toPlay.push_back(Playlist("default"));

int choice = 0;

do {

cout << " *************************************************** "

"* * "

"* Playlist Manager DJ * "

"* * "

"*************************************************** "

"Where would you like to start? "

"1. Add Songs "

"2. Add New Playlist "

"3. View All Playlists "

"4. Save All Playlists on file "

"5. Exit "

"Enter Your Choice: ";

cin >> choice;

cin.ignore(1);

// Set the numeric output formatting.

cout << std::fixed << std::showpoint << std::setprecision(2);

// Respond to the user's menu selection.

switch (choice) {

case 1: // Add songs to a playlist

addSongs(toPlay.at(0));

break;

case 2:

addNewPlaylist(toPlay);

break;

case 3:

displayAllPlaylists(toPlay);

break;

case 4:

saveonFile(toPlay);

break;

case 5:

cout << "Happy Listening! ";

choice = exitMenuChoice();

break;

default:

break;

}

} while (0 < choice && choice < 5);

waitForEnter();

return 0;

}

void displayPlaylist(Playlist list)

{

cout << "This is Playlist '" << list.name << "': ";

cout << "title: \t\t; artist: \t; genre:\t; duration " << endl;

for (int i = 0; i < list.songList.size(); i++) {

Song s = list.songList.at(i);

//print song title

cout << s.songTitle << "\t" << s.artistName

<< "\t" << s.songGenre << "\t" << s.songLength

<< ' ';

}

//print total length and average song length of play list

cout << "and the length is : " << list.length << endl;

double songLengthAvg = list.length / list.songList.size();

cout << "The average song length in this playlist is: " << songLengthAvg << endl;

}

Playlist& addSongs(Playlist &play)

{

string title;

do {

int i = 1;

cout << " Insert new song into playlist"

" - leave title empty to end insertion."

" Enter title of song# " << i << ": ";

getline(cin, title);

if (title.empty()) { break; }

cout << "Enter artist for this song: ";

string artist;

getline(cin, artist);

cout << "Enter genre for this song: ";

string genre;

getline(cin, genre);

cout << "Enter duration for this song: ";

double song_duration = 0.0;

cin >> song_duration;

cin.ignore(1);

cout << " Adding " << genre << " song \"" << title

<< "\" by " << artist << ". Running time: "

<< song_duration << " mins ";

i++;

Song song(title, artist, genre, song_duration);

play.addSong(song);

} while (not title.empty());

return play;

}

vector& addNewPlaylist(vector& play)

{

cout << " Enter Playlist Name: ";

string n_playlist;//read name of the list

getline(std::cin, n_playlist);

Playlist just_created(n_playlist);

cout << " Your new playlist " << n_playlist << " has been added! ";

char option = 'n';

do {

cout << "Would you like to add songs to your new playlist "

<< n_playlist << "? (Y/N) ";

cin >> option;//read user option

cin.ignore(1);

option = toupper(option);

} while (option not_eq 'Y' and option not_eq 'N');

if (option == 'Y') { addSongs(just_created); }

play.push_back(just_created);//insert new list in vector

return play;

}

void displayAllPlaylists(const vector& plays)

{

for (int i = 0; i < plays.size(); i++)

{

displayPlaylist(plays.at(i)); //print each play list

cout << endl << endl;

}

}

//Exit Menu

int exitMenuChoice()

{

cout << " Would you like to exit the program? (Y/N) ";

char answ = 'N';

cin >> answ;

cin.ignore(1);

if (answ == 'Y' || answ == 'y') {

return 5;

}

return 3; // == show playlists

}

void waitForEnter()

{

cout << " Press ENTER to continue... ";

cin.ignore(std::numeric_limits::max(), ' ');

}

void saveonFile(const std::vector& plays)

{

ofstream outfile("allSongs.txt");//create output file

for (int i = 0; i < plays.size(); i++)

{

Playlist list = plays.at(i);

for (int j = 0; j < list.songList.size(); j++) {

Song s = list.songList.at(j);

//print songs on file

outfile << s.songTitle << "\t" << s.artistName

<< "\t" << s.songGenre << "\t" << s.songLength

<< ' ';

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!