Question: Program Description Both the Java and C++ programs have the same functionality, as described below. The Java solution will require at least two files: MediaDescription.java

Program Description Both the Java and C++ programs have the same functionality, as described below. The Java solution will require at least two files: MediaDescription.java and MediaLibrary.java. The C++ solution should consist of five files: MediaLibrary.hpp, MediaLibrary.cpp, MediaDescription.hpp, MediaDescription.cpp, and main.cpp.

MediaDescription is a class that wraps the properties of a music or video file. Place the following properties in your MediaDescription class.

mediaType Its value should either Music, or Video.

title The title of the song or the video/movie.

author The artist of a song or the leading actor/actress of video.

album Unused for videos, but is used to group related songs.

genre Used to group videos.

filename The file name in whic the media is stored. Most commonly the is title.mp3 or title.mp4

Provide constructors accessor and getter methods as appropriate. Provide a toString() method for a MediaDescription object which returns a string suitable for printing.

The MediaLibrary class should provide storage and management for a collection of media. The library is used to store MediaDescription objects. In future assignments, the MediaLibrary will become a server running on the Raspberry Pi. Clients will connect to the server and use the methods provided by the MediaLibrary to create a user-interface for browsing and playing media. You may assume that all titles stored in a library object are unique. YourMediaLibrary class should provide the following methods.

public boolean add(MediaDescription aClip); A method to add a new song or video the library. True is returned when the request is successful.

public boolean remove(String aTitle); A method to remove the named MediaDescription from the library.

public MediaDescription get(String aTitle); Returns the media description with title aTitle.

public String[] getTitles(); Returns an array of strings, which are all of the titles in the library.

public String[] getMusicTitles(); Returns an array of strings, which are all of the music titles in the library.

public String[] getVideoTitles(); Returns an array of strings, which are all of the video titles in the library.

For your C++ version of MediaLibrary you may find it easier to return a std::vector rather than an array of strings. Thus the signature of getTitles would be: std::vector getTitles(); //returns a vector of strings of all media titles in the library

So I have a fully functional .java and am having difficulty with the C++ side of things. I believe that my MediaDescription.hpp and .cpp are fine but not my MediaLibrary.hpp and.cpp

Here is what I have:

MediaDescription.hpp

#include

using namespace std;

class MediaDescription { public: //Constructors MediaDescription(); MediaDescription(string, string, string, string, string, string); //Setters void setMediaType(string); void setTitle(string); void setAuthor(string); void setAlbum(string); void setGenre(string); void setFilename(string); //Getters string getMediaType(); string getTitle(); string getAuthor(); string getAlbum(); string getGenre(); string getFilename(); //toString string toString(); private: string mediaType, title, author, album, genre, filename; };

MediaDescription.cpp

#include "MediaDescription.hpp" #include #include

//Specified Constructor MediaDescription::MediaDescription(string mediaType, string title, string author,string album, string genre, string filename): mediaType(mediaType), title(title), author(author), album(album), genre(genre), filename(filename) {}

//Null Constructor MediaDescription::MediaDescription(): mediaType(""), title(""), author(""), album(""), genre(""), filename("") {}

//Setters void MediaDescription::setMediaType(string mediaType){this->mediaType = mediaType;} void MediaDescription::setAuthor(string author){this->author = author;} void MediaDescription::setTitle(string title){this->title = title;} void MediaDescription::setAlbum(string album){this->album = album;} void MediaDescription::setGenre(string genre){this->genre = genre;} void MediaDescription::setFilename(string filename){this->filename = filename;}

//Getters string MediaDescription::getMediaType(){return this->mediaType;} string MediaDescription::getAuthor(){return this->author;} string MediaDescription::getTitle(){return this->title;} string MediaDescription::getAlbum(){return this->album;} string MediaDescription::getGenre(){return this->genre;} string MediaDescription::getFilename(){return this->filename;}

//toString string MediaDescription::toString(){ char* x = new char[getMediaType().length()+getAuthor().length()+getTitle().length()+ getAlbum().length()+getGenre().length()+getFilename().length()]; sprintf(x, "%25s %25s %25s %25s %25s %25s", getMediaType().c_str(), getAuthor().c_str(), getTitle().c_str(), getAlbum().c_str(), getGenre().c_str(), getFilename().c_str()); string str = x; return str; }

MediaLibrary.hpp

#include "MediaDescription.hpp" #include #include

using namespace std;

class MediaLibrary {

public: MediaLibrary(); ~MediaLibrary(); bool add(MediaDescription aClip); bool remove(string aTitle); MediaDescription get(string); vector getTitles(); vector getMusicTitles(); vector getVideoTitles(); void toStringTitles(string, vector); string toString();

private: vector * mediaList; vector * musicTitles; vector * videoTitles; };

MediaLibrary.cpp

#include "MediaLibrary.hpp" #include #include

using namespace std;

MediaLibrary::MediaLibrary(){ mediaList = new vector(); musicTitles = new vector(); videoTitles = new vector(); } MediaLibrary::~MediaLibrary(){delete mediaList, musicTitles, videoTitles;}

bool MediaLibrary::add(MediaDescription aClip){ string mediaType = aClip.getMediaType(); string title = aClip.getTitle(); string author = aClip.getAuthor(); string album = aClip.getAlbum(); string genre = aClip.getGenre(); string filename = aClip.getFilename(); bool isMusic = string("Music").compare(mediaType)==0; bool isVideo = string("Video").compare(mediaType)==0;

if(isMusic){ musicTitles->push_back(title); // mediaList->push_back(aClip); // mediaList->push_back(mediaType + ": \"" + title + "\" by " + author // + " Album: " + album + " Genre: " + genre + " Filename: " + filename); } else if(isVideo){ videoTitles->push_back(title); // mediaList->push_back(aClip); // mediaList->push_back(mediaType + ": \"" + title + "\" by " + author // + " Genre: " + genre + " Filename: " + filename); } return true; }

bool MediaLibrary::remove(string aTitle){ // vector::iterator result = mediaList->begin; // // while(result != mediaList->end()){ // if(*result == aTitle){ // mediaList->erase(result); // return true; // } // else // result++; // } return true; } // //MediaDescription MediaLibrary::get(string aTitle){ // // cout << mediaList->size(); // for(int i=0; isize(); ++i){ // if(mediaList->at(i).compare(aTitle) == 0) // return mediaList[i]; // } // return *mediaList; //}

vector MediaLibrary::getTitles(){ vector titleVector; //Create new vector for all titles titleVector.reserve(musicTitles->size()+videoTitles->size()); titleVector.insert(titleVector.end(), musicTitles->begin(), musicTitles->end()); titleVector.insert(titleVector.end(), videoTitles->begin(), videoTitles->end()); return titleVector; }

std::vector MediaLibrary::getMusicTitles(){return *(this->musicTitles);} std::vector MediaLibrary::getVideoTitles(){return *(this->videoTitles);}

void MediaLibrary::toStringTitles(string mediaType, std::vector titles){ cout << mediaType << " titles in the library: "; for(int i=0;i

string MediaLibrary::toString(){ string str = ""; for(int i = 0; isize(); ++i) mediaList->at(i); return str; }

Main.cpp

#include "MediaLibrary.hpp" #include #include #include

using namespace std;

int main(){ MediaLibrary myLib; //Fill library myLib.add(MediaDescription("Music","Come Monday","Jimmy Buffett","Greatest Hits","Island","ComeMonday.mp3")); myLib.add(MediaDescription("Music","Fins","Jimmy Buffett","Greatest Hits","Island","Fins.mp3")); myLib.add(MediaDescription("Video","Banana Song","Minions","","Animation","minionsbananasong.mp4")); myLib.add(MediaDescription("Video","Banana","Minions","","Animation","minionsbanana.mp4"));

//Print all titles myLib.toStringTitles("All", myLib.getTitles());

//Print music titles myLib.toStringTitles("Music", myLib.getMusicTitles()); //Print video titles myLib.toStringTitles("Video", myLib.getVideoTitles());

// //Remove a title // cout << "Removing: Come Monday" << endl; // myLib.remove("Come Monday"); // if(myLib.remove("Come Monday")) // cout << "Removal Successful" << endl; // else // cout << "Removal Unsuccessful" << endl; MediaDescription my; cout << my.toString(); //Print all titles after removal cout << myLib.toString(); return 0; }

I need the most help with the add, remove and get methods in MediaLibrary.cpp. I should be able to square away from there.

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!