Question: C++ 1. (100%) Modify the class Song you created in Assignment 2 by doing the following: (a) Add methods title(), artist() and year() that return,

C++

1. (100%) Modify the class Song you created in Assignment 2 by doing the following:

(a) Add methods title(), artist() and year() that return, re- spectively, the title, artist and recording year of the song. The first two functions return a string by constant reference. The third one returns an integer.

(b) Add methods set_title(title), set_artist(artist) and set_year(year) that set the title, artist and recording year of the song to the given values. The first two methods take a string as ar- gument, the third one takes an integer.

(c) Add a method set(title, artist, year) that sets the title, artist and recording year of the song to the given values. The first two arguments are strings, the third one is an integer.

(d) Replace the equals method by an equality operator (==).

(e) Replace the less_than method by an equality operator (<).

Previous Code from Assignment 2 (Needs to be fixed):

#include

#include

using namespace std;

class Song

{

private:

string title;

string artist;

int year;

public:

Song()

{

title = "invalid";

artist = "invalid";

year = -1;

}

Song(string_title)

{

title = _title;

artist = "unknown";

year = -1;

}

Song(string_title, string_artist, int_year)

{

title = title;

artist = artist;

year = year;

}

void print(ostream& out)

{

cout << "Title" << title << endl;

cout << "Artist" << artist << endl;

cout << "Year" << year << endl;

}

void read(istream& in)

{

getline(in, title);

getline(in, artist);

cin >> year;

cin.ignore();

}

bool equals(const Song& other)

{

if (title == other.title && artist == other.artist && year == other.year)

{

return true;

}

else

{

return false;

}

}

bool less_than(const Song& other)

{

if(title < other.title)

{

return true;

}

else if(title == other.title && artist < other.artist)

{

return true;

}

else if(title == other.title && artist == other.artist && year < other.year)

{

return true;

}

else

{

return false;

}

};

int main ()

{

Song s1 ("", '", "");

Song s2 ("", "", "");

Song s3 ("", "", "");

s3.print (cout);

cout << endl;

s2.print (cout);

cout << endl;

cout << "Song 1: Enter title, artist, and year:" << endl;

s1.read (cin);

cout << "Song 2: Enter title, artist, and year:" << endl;

s2.read (cin);

cout << "Song 3: Enter title, artist, and year:" << endl;

s3.read (cin);

return 0;

}

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!