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
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
//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
using namespace std;
class MediaLibrary {
public: MediaLibrary(); ~MediaLibrary(); bool add(MediaDescription aClip); bool remove(string aTitle); MediaDescription get(string); vector
private: vector
MediaLibrary.cpp
#include "MediaLibrary.hpp" #include
using namespace std;
MediaLibrary::MediaLibrary(){ mediaList = new vector
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
vector
std::vector
void MediaLibrary::toStringTitles(string mediaType, std::vector string MediaLibrary::toString(){ string str = ""; for(int i = 0; i Main.cpp #include "MediaLibrary.hpp" #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
Get step-by-step solutions from verified subject matter experts
