Question: C++ media player playlist help: Need to create a Playlist Class includes playlist.h and playlist.cpp. The playlist class needs to contain variables: - playName: string

C++ media player playlist help:

Need to create a Playlist Class includes playlist.h and playlist.cpp. The playlist class needs to contain variables: - playName: string - playDate: string - userId: string Playlist class needs to contain methods: - create() - delete() - add() - show() - isEmpty() - getNumItems()

Not only songs will be in the Playlist, below I have included a Database class, FileManager class, makefile, media class, song class, and test class. Will need to create a Playlist Class which includes playlist.h and playlist.cpp. As well as edits to any other classes to make playlist class work.

********Database.h********

#ifndef DATABASE_H #define DATABASE_H #include #include #include #include #include "Song.h" class Database { private: Database(); static Database* _Instance; std::vector Songs; public: static Database* Instance(); std::vector* SongDB(); }; #endif

********Database.cpp********

#include "Database.h" Database* Database::_Instance = NULL; Database::Database() { } Database* Database::Instance() { if (_Instance == NULL) { _Instance = new Database; } return _Instance; } std::vector* Database::SongDB() { return &Songs; } 

********FileManager.h********

#ifndef FM_H #define FM_H #include #include #include #include #include "Database.h" #include "Song.h" #include "Media.h" class FileManager { private: FileManager(); static FileManager* _Instance; public: static FileManager* Instance(); int addSong(Song tmp); int delSong(std::string addr); int refreshDB(); }; #endif

********FileManager.cpp********

#include "FileManager.h" FileManager* FileManager::_Instance = NULL; FileManager::FileManager() { } FileManager* FileManager::Instance() { if (_Instance == NULL) { _Instance = new FileManager; } return _Instance; } int FileManager::addSong(Song tmp) { std::vector *SDB; SDB = Database::Instance() -> Database::SongDB() ; SDB -> push_back(tmp); return 0; } int FileManager::delSong(std::string addr) { std::vector *SDB; Song *listed; SDB = Database::Instance() -> Database::SongDB(); for (int i = 0; i < SDB -> size(); ++i) { listed = &(SDB -> at(i)); if ((listed -> getAddr()) == addr) { SDB -> erase(SDB -> begin() + i); return true; } } } int FileManager::refreshDB() { struct dirent * dp; std::string addr; std::string dir; DIR* dirp = opendir("./Music"); //for all files under the Music directory dp = readdir(dirp); dp = readdir(dirp); while ((dp = readdir(dirp)) != NULL) { addr = "Music/" ; addr.append(dp->d_name); FileManager::addSong(Song(addr)); } }
********makefile******** 
Media: Media.cpp Media.h g++ -o Media Media.cpp Media.o: Media.cpp Media.h g++ -c Media.cpp Song.o: Song.cpp Song.h g++ -c Song.cpp Song: Media.o Song.o g++ -o Final Media.o Song.o Database.o: Database.cpp Database.h g++ -c Database.cpp FileManager.o: FileManager.cpp FileManager.h g++ -c FileManager.cpp test.o: main.cpp All: Test.o Media.o Song.o Database.o FileManager.o g++ -o Test Test.o Media.o Song.o Database.o FileManager.o

********Media.h********

#ifndef MEDIA_H #define MEDIA_H #include #include class Media { protected: std::string fileName; std::string fileType; std::string fileDirt; void setFile(std::string fileD); Media(); public: Media(std::string fileD); friend std::ostream& operator<<(std::ostream& os, const Media& tmp); }; #endif

********Media.cpp********

#include "Media.h" Media::Media() { fileName = ""; fileType = ""; fileDirt = ""; } Media::Media(std::string file) { setFile(file); } void Media::setFile(std::string fileD) { std::size_t found = fileD.find_first_of("/"); fileDirt = fileD.substr(0, found); std::string nameT = fileD.substr(found+1); found = nameT.find("."); fileName = nameT.substr(0, found); fileType = nameT.substr(found+1); } std::ostream& operator<<(std::ostream& os, const Media& tmp) { os << "Name: " << tmp.fileName << " "; os << "Directory: " << tmp.fileDirt << " "; os << "File Type: " << tmp.fileType << " "; return os; }

********Song.h********

#ifndef SONG_H #define SONG_H #include "Media.h" #include #include class Song : private Media { private: std::string title; std::string author; std::string genre; std::string length; public: Song(std::string fileD); friend std::ostream& operator<<(std::ostream& os, const Song& tmp); void setTitle(std::string tmp); void setAuthor(std::string tmp); void setGenre(std::string tmp); void setLength(int tmp); std::string getAddr(); }; #endif

********Song.cpp********

#include "Song.h" Song::Song(std::string fileD) { Media::setFile(fileD); title = fileName; author = ""; genre = ""; length = ""; } std::ostream& operator<<(std::ostream& os, const Song& tmp) { os << "Name: " << tmp.fileName << " "; os << "Directory: " << tmp.fileDirt << " "; os << "File Type: " << tmp.fileType << " "; os << "Song Title: " << tmp.title << " "; os << "Song Author: " << tmp.author << " "; os << "Song Genre: " << tmp.genre << " "; os << "Song Length: " << tmp.length << " "; return os; } void Song::setTitle(std::string tmp) { title = tmp; } void Song::setAuthor(std::string tmp) { author = tmp; } void Song::setGenre(std::string tmp) { genre = tmp; } void Song::setLength(int tmp) { int min = tmp / 60; int sec = tmp % 60; length = std::to_string(min) + " min " + std::to_string(sec) + " sec"; } std::string Song::getAddr() { std::string addr = fileDirt + "/" + fileName + "." + fileType; return addr; }

********Test.cpp********

#include "FileManager.h" int main() { FileManager *FM = FileManager::Instance(); FM -> refreshDB(); std::vector *SDB; SDB = Database::Instance() -> Database::SongDB() ; std::string addr = "Music/04.txt"; FM -> delSong(addr); for (std::vector::iterator it = SDB -> begin() ; it != SDB -> end(); ++it) { std::cout << *it; } }

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!