Cis 170 Week 7 Project-Song Playlist Program

01 August, 2024 | 3 Min Read

CIS170C

Week 6 Course Project

Professor Clyde Gander

#include < cctype >

#include < iomanip >

#include < iostream >

#include < fstream >

#include < limits >

#include < string > #include < vector > using namespace std;

//class for Songs class Song { public:

string artist; string title; string genre; float length;

Song(string a, string t, string g, float l) ; void displayDetails();

} ;

//constructor for song class

Song::Song(string a, string t, string g, float l) { artist = a; title = t; genre = g; length = l;

}

//functio to display song details void Song:: displayDetails() { cout << “Artist: " << artist << “\n”; cout << “Song title: " << title << “\n”; cout << “Song genre: " << genre << “\n”; cout << “Length: " << length << “\n”;

}

//class for playlist of songs class PlayList { public:

string title; vector<Song> plt;

PlayList(string t) ; void addSong(Song s) ;

} ;

//constructor for PlayList class

PlayList::PlayList(string t) { title = t;

}

//function to add song to the vector void PlayList::addSong(Song s) { plt.push_back(s) ;

}

//function to create playlist void createPlayList(vector<PlayList> &p) { if (p.size() >= 10) {

cout << “You have entered the maximum of 10 playlist! Returning to

the Home Page” << endl << endl; return;

}

string name; char choice = ‘Y’; string artist, title, genre; float length; int songCount = 0;

cin.ignore();

cout << “Enter Playlist Name: “; getline(cin, name);

//creating an object of PlayList class

PlayList p1(name); do { if (songCount == 10) { cout << “You have entered the maximum of 10 songs! Returning

to the Home Page” << endl << endl; break;

}

cout << “You have entered [” << songCount << “] songs” << endl <<

endl; cout << “Insert the artist’s name: “;

// artist name getline(cin, artist);

cout << “Insert the title of the song: “;

//songs title getline(cin, title);

cout << “Insert the genre of the song: “;

//song genre getline(cin, genre);

cout << “Insert the song length: “;

//length of song cin » length;

//creating a Song class object and addin it to PlayList class object

Song s(artist, title, genre, length); p1.addSong(s);

songCount += 1;

cout << “Would you like to add another song?(Y/N): “; cin » choice; cin.ignore();

} while (choice == ‘Y’ || choice == ‘y’) ;

//puching each playlist created to a PlayList vector

p.push_back(p1);

}

//functoin to display playlists and all sngs in it void displayPlayList(vector<PlayList> p) { if (p.size() == 0) { cout << “You have no Playlists!” << endl << endl; }

else {

cout << " Your playlists” << endl; cout << “————————-” << endl; for (int i = 0; i < p.size(); i++) { cout << “PlayList: " << p[i].title << “\n”; cout << “===================================\n”; for (int j = 0; j < p[i].plt.size(); j++) { p[i].plt[j].displayDetails();

}

}

cout << “\n”;

}

}

//main method int main() { char choice = ‘y’; int numChoice; vector<PlayList> p1;

//display menu to user untill user exits while (1) { cout << “========================================” << endl; cout << " Your Playlist Manager! " << endl;

cout << “========================================” << endl << endl;

// choose a path

cout << “1. Create New Playlist” << endl; cout << “2. Display All Playlists” << endl; cout << “3. Exit” << endl << endl; cout << “What Do You Want To Do? [1-3]: “; cin » numChoice;

switch (numChoice) { case 1: createPlayList(p1); break;

case 2: displayPlayList(p1); break;

case 3: cout << “Exiting!!!!!!\n”; exit(0);

default: cout << “Invalid choice, Please re-enter\n”;

} cout << “\n\n”;

}

return 0;

Related posts