Question: C++ overloaded operators Use the guidance below implement operator== and operator- == returns true if the title and artist of the song are the same;

C++ overloaded operators

Use the guidance below

implement operator== and operator-

== returns true if the title and artist of the song are the same; write this operator as a member function of the Song class

- returns the difference in seconds between the lengths of the songs; write this function as a free function outside the Song class

#include using namespace std;

class Song{ string songname; string singer; int time; int sec; int min; public: string play (Song); Song(string songname, string singer, int time); void play(){ cout << "Played \"" << songname <<"\" by " << singer << " for " << min <<":" << sec <songname=songname; this->singer =singer; this->time =time; min= time/60; sec= time-(min*60); }

int main(int argc, char **argv) { Song s1("Black Hole Sun", "SoundGarden", (3*60)+41); Song s2("Nevermind", "Nirvana", (2*60)+56); Song s3("GrandHotel", "Regina Spektor", (3*60)+50); Song s4("LastNight ", "The Strokes", (4*60)+9);

cout << "s1 == s2: " << (s1 == s2) << endl; cout << "s1 == s3: " << (s1 == s3) << endl; cout << "s3 == s4: " << (s3 == s4) << endl; cout << "s2 == s2: " << (s2 == s2) << endl;

cout << "s1 - s2: " << (s1 - s2) << endl; cout << "s3 - s4: " << (s3 - s4) << endl; cout << "s4 - s3: " << (s4 - s3) << endl; cout << "s2 - s2: " << (s2 - s2) << endl; cout << "s2 - s4: " << (s2 - s4) << endl; }

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!