Design, implement, and test a class that represents a song on a CD. It should ha
ID: 3592065 • Letter: D
Question
Design, implement, and test a class that represents a song on a CD. It should have members for title, album, artist, playing time in minutes and seconds and music category. The class should have a constructor that allows all of the data members to be set, and a default constructor that sets all of the data members to appropriate empty values. It should have an observer operation for each data members and an observer that returns all of the data for the song as a string. An observer that compares two songs for equality should be developed as well. Submission should include: UML class diagram, header file and C++ source code, screen shot of output.
Explanation / Answer
Design, implement, and test a class that represents a song on a CD or in an MP3 library. If you did Programming Warm-Up Exercises 4 through 6, you already have a good start. It should have members for title, album, artist, playing time in minutes and seconds, and music category. The music category is represented by an enumeration type calledCategory; make up an enumeration of your favorite categories. The class should have a constructor that allows all of the data members to be set, and a default constructor that sets all of the data members to appropriate empty values. It should have an observer operation for each data member, and an observer that returns all of the data for the song as a string. An observer that compares two songs for equality should be developed as well.
Edit & Run
//Song Class #ifndef SONG_CLASS #define SONG_CLASS using namespace std; class Song { private: string title; //dynamic allocation string album; string genre; string artist; double durationn; public: Song(); void setTitle(string t); void setDuration(double d); void setAlbumName(string a); void setGenre(string g); void setArtist(string a); string getTitle(); string getAlbum()const; string getGenre()const; string getArtist()const; double getDuration)(); //accessor }; //constructor Song::Song() //constructor { title=""; album=""; genre=""; artist=""; duration=0; } //accessor for name string Song::getTitle() { return title; } //mutator void Song::setTitle(string t) { title=t; } //accessor for name string Song::getAlbum() { return album; } //mutator void Song::setAlbumName(string a) { album=a; } //accessor for name string Song::getGenre() { return genre; } //mutator void Song::setGenre(string g) { genre=g; } //accessor for name string Song::getArtist() { return artist; } //mutator void Song::setArtist(string s) { artist=s; } void Song::setDuration(double d) { duration=d; } double Song::getDuration() { return duration; } #endif // SONG_CLASS //FOR THE .CPP I DO NOT KNOW HOW TO DISPLAY IT THERE. CAN ANYONE HELP? //file test.cpp #include <iostream> #include <fstream> #include <string> #include "song.h" using namespace std; int main() { return 0; } Edit & Run
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.