Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ class called Song to represent a song in a music collection. The dat

ID: 3623261 • Letter: W

Question

Write a C++ class called Song to represent a song in a music collection. The data members of the Song class are strings representing the song title, artist’s name, and the album where the song can be found. These instance variables for the class are to have private access modifiers so I need to write the appropriate functions to allow a client to access and modify the data values. In addition, I need to write an overloaded equality (==) function; two songs are equal if they have the same title, artist, and album, regardless of the case of the letters. I also need to implement an overloaded greater-than (>) function because I will be using this program throughout the semester.

A second file is to be written called SongList that contains a main function and separate function to display a menu of options for the user. The menu will contain options that allow the user to:

1. Add a song
2. Remove a song
3. Display all the songs in the list
4. Quit


****Just a quick note: Someone asked the same question a little while ago but the answer was wrong. I tested the solution and it did not work.

Explanation / Answer

Only thing I could not figure out was how to successfully delete an entire song object from the vector I created in the driver. This should give you a nice start though. Please Rate! DRIVER PROGRAM
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include "song.h" using namespace std; // Prototypes void getInput(song); int main() { song test; getInput(test); system("PAUSE"); return EXIT_SUCCESS; } // Definitions void getInput(song x) { vector <song> songVec; int userInput; bool keepGoing = true; string song, artist, album; cout << "1. Add a Song "; cout << "2. Remove a Song "; cout << "3. Display All Songs "; cout << "4. Quit "; cout << "-------------------------------------------- "; while (keepGoing) { cout << "Please Select an Option from the list: "; cin >> userInput; cin.ignore(); switch (userInput) { case 1 : { cout << " Enter the Artist's name: "; getline(cin, artist); cout << "Enter the Song Title: "; getline(cin, song); cout << "Enter the album its from: "; getline(cin, album); cout << " "; x.setArtist(artist); x.setAlbum(album); x.setTitle(song); songVec.push_back(x); } break; case 2 : { int choice; cout << " Select A Song to Remove from the list"; for (size_t i = 0; i < songVec.size(); i++) { cout << " Option #" << i+1 << ": " << songVec[i].getTitle(); } cout << " Your choice: "; cin >> choice; songVec[choice-1].setArtist(""); songVec[choice-1].setTitle(""); songVec[choice-1].setAlbum(""); } break; case 3 : { for (size_t i = 0; i < songVec.size(); i++) { cout << " Artist: " << songVec[i].getArtist(); cout << " Album: " << songVec[i].getAlbum(); cout << " Title: " << songVec[i].getTitle(); cout << " "; } } break; default: keepGoing = false; break; } } } HEADER FILE #include <string> #include <cstdlib> using namespace std; #ifndef SONG #define SONG class song { public: // Constructor song(string userArtist = "Meat Puppers", string userTitle = "Lost", string userAlbum = "Meat Puppets II"); void setTitle(string newTitle); // Set the title void setArtist(string newArtist); // Set the artist void setAlbum(string newAlbum); // Set the album string getTitle() const; // Get the current song title string getArtist() const; // Get the current song artist string getAlbum() const; // Get the current song album private: string title, artist, album; // Private Variables friend bool operator ==(const song &initial, const song &second); // Overloaded == friend bool operator >(const song &initial, const song &second); // Overloaded > }; #endif IMPLEMENTATION FILE #include "song.h" song::song (string userArtist, string userTitle, string userAlbum) { artist = userArtist; title = userTitle; album = userAlbum; } void song::setTitle(string newTitle) { title = newTitle; } void song::setArtist(string newArtist) { artist = newArtist; } void song::setAlbum(string newAlbum) { album = newAlbum; } string song::getTitle() const { return title; } string song::getArtist() const { return artist; } string song::getAlbum() const { return album; } bool operator ==(const song& initial, const song& second) { if (initial.artist == second.artist && initial.title == second.title && initial.album == second.album) return true; return false; } bool operator > (const song &initial, const song &second) { if (initial.artist > second.artist && initial.title > second.title && initial.album > second.album) return true; return false; }
Only thing I could not figure out was how to successfully delete an entire song object from the vector I created in the driver. This should give you a nice start though. Please Rate! DRIVER PROGRAM
#include <iostream> #include <string> #include <vector> #include <cstdlib> #include "song.h" using namespace std; // Prototypes void getInput(song); int main() { song test; getInput(test); system("PAUSE"); return EXIT_SUCCESS; } // Definitions void getInput(song x) { vector <song> songVec; int userInput; bool keepGoing = true; string song, artist, album; cout << "1. Add a Song "; cout << "2. Remove a Song "; cout << "3. Display All Songs "; cout << "4. Quit "; cout << "-------------------------------------------- "; while (keepGoing) { cout << "Please Select an Option from the list: "; cin >> userInput; cin.ignore(); switch (userInput) { case 1 : { cout << " Enter the Artist's name: "; getline(cin, artist); cout << "Enter the Song Title: "; getline(cin, song); cout << "Enter the album its from: "; getline(cin, album); cout << " "; x.setArtist(artist); x.setAlbum(album); x.setTitle(song); songVec.push_back(x); } break; case 2 : { int choice; cout << " Select A Song to Remove from the list"; for (size_t i = 0; i < songVec.size(); i++) { cout << " Option #" << i+1 << ": " << songVec[i].getTitle(); } cout << " Your choice: "; cin >> choice; songVec[choice-1].setArtist(""); songVec[choice-1].setTitle(""); songVec[choice-1].setAlbum(""); } break; case 3 : { for (size_t i = 0; i < songVec.size(); i++) { cout << " Artist: " << songVec[i].getArtist(); cout << " Album: " << songVec[i].getAlbum(); cout << " Title: " << songVec[i].getTitle(); cout << " "; } } break; default: keepGoing = false; break; } } } HEADER FILE #include <string> #include <cstdlib> using namespace std; #ifndef SONG #define SONG class song { public: // Constructor song(string userArtist = "Meat Puppers", string userTitle = "Lost", string userAlbum = "Meat Puppets II"); void setTitle(string newTitle); // Set the title void setArtist(string newArtist); // Set the artist void setAlbum(string newAlbum); // Set the album string getTitle() const; // Get the current song title string getArtist() const; // Get the current song artist string getAlbum() const; // Get the current song album private: string title, artist, album; // Private Variables friend bool operator ==(const song &initial, const song &second); // Overloaded == friend bool operator >(const song &initial, const song &second); // Overloaded > }; #endif IMPLEMENTATION FILE #include "song.h" song::song (string userArtist, string userTitle, string userAlbum) { artist = userArtist; title = userTitle; album = userAlbum; } void song::setTitle(string newTitle) { title = newTitle; } void song::setArtist(string newArtist) { artist = newArtist; } void song::setAlbum(string newAlbum) { album = newAlbum; } string song::getTitle() const { return title; } string song::getArtist() const { return artist; } string song::getAlbum() const { return album; } bool operator ==(const song& initial, const song& second) { if (initial.artist == second.artist && initial.title == second.title && initial.album == second.album) return true; return false; } bool operator > (const song &initial, const song &second) { if (initial.artist > second.artist && initial.title > second.title && initial.album > second.album) return true; return false; } #include <string> #include <cstdlib> using namespace std; #ifndef SONG #define SONG class song { public: // Constructor song(string userArtist = "Meat Puppers", string userTitle = "Lost", string userAlbum = "Meat Puppets II"); void setTitle(string newTitle); // Set the title void setArtist(string newArtist); // Set the artist void setAlbum(string newAlbum); // Set the album string getTitle() const; // Get the current song title string getArtist() const; // Get the current song artist string getAlbum() const; // Get the current song album private: string title, artist, album; // Private Variables friend bool operator ==(const song &initial, const song &second); // Overloaded == friend bool operator >(const song &initial, const song &second); // Overloaded > }; #endif IMPLEMENTATION FILE #include "song.h" song::song (string userArtist, string userTitle, string userAlbum) { artist = userArtist; title = userTitle; album = userAlbum; } void song::setTitle(string newTitle) { title = newTitle; } void song::setArtist(string newArtist) { artist = newArtist; } void song::setAlbum(string newAlbum) { album = newAlbum; } string song::getTitle() const { return title; } string song::getArtist() const { return artist; } string song::getAlbum() const { return album; } bool operator ==(const song& initial, const song& second) { if (initial.artist == second.artist && initial.title == second.title && initial.album == second.album) return true; return false; } bool operator > (const song &initial, const song &second) { if (initial.artist > second.artist && initial.title > second.title && initial.album > second.album) return true; return false; } #include "song.h" song::song (string userArtist, string userTitle, string userAlbum) { artist = userArtist; title = userTitle; album = userAlbum; } void song::setTitle(string newTitle) { title = newTitle; } void song::setArtist(string newArtist) { artist = newArtist; } void song::setAlbum(string newAlbum) { album = newAlbum; } string song::getTitle() const { return title; } string song::getArtist() const { return artist; } string song::getAlbum() const { return album; } bool operator ==(const song& initial, const song& second) { if (initial.artist == second.artist && initial.title == second.title && initial.album == second.album) return true; return false; } bool operator > (const song &initial, const song &second) { if (initial.artist > second.artist && initial.title > second.title && initial.album > second.album) return true; return false; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote