Question
original code: #include #include #include using namespace std; class Song { private: int year = 0; string title; string artist; public: // Print the details
original code:
#include
class Song { private: int year = 0; string title; string artist;
public: // Print the details of the song void print(const Song& s, ostream& out) { out > s.year; in.ignore(); } // Check if two songs are the same bool equals(const Song& s2) {
return this->title == s2.title && this->artist == s2.artist && this->year == s2.year; } };
int main() {
// Test Drivers Song s1, s2; s1.read(s1, cin);
s2.read(s2, cin);
s1.print(s1, cout);
s2.print(s2, cout);
if (s1.equals(s2)) { cout
return 0; }
1. (100%) Modify the class Song you created in Assignment 1 by doing the following: (a) Add a default constructor that initializes the song to have invalid as title and artist, and -1 as recording year. (b) Add a constructor Song(title) that initializes the song to the given title (that is, to the title given as argument). The artist and recording year are initialized to unknown and -1, respectively. The argument is a string. (c) Add a constructor Song (title, artist, year) that initializes the song to the given title, artist and recording year. The first two arguments are strings, the third one is an integer. (d) Replace the function print (s, out) by a method print (out) that prints the song to output stream out in the same format as be- fore: Title Artist Year Three complete lines should be printed. 1 (e) Replace the function read(s, in) by a method read (in) that reads the song from input stream in. The data in the stream is as- sumed to be in the format specified for print. In particular, three complete lines should be read. No error-checking is performed. (f) Replace the function equals(s1, s2) by a method equals (other) that returns true if the receiver and the argument have the same title, artist and recording year. (g) Add a method less_than (other) that returns true if the title of the first song is less than the title of the second song. In case the titles of the two songs are identical, the operator returns true if the artist of the first song is less than the artist of the second song. In case the titles and artists of the two songs are identical, the operator returns true if the first song was recorded before the second one. In all other cases, the operator returns false. Titles and artists are compared with respect to alphabetical order. (You can useStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started