Could you help me with this C++ code please: Modify the class Song you created by doing the following: (a) 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 argument, the third one takes an integer. (b) 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. (c) Replace the equals method by an equality operator (==). (d) Replace the less_than method by a less-than operator (<). (e) Replace the print method by an output operator (<<). (f) Replace the read method by an input operator (>>). (g) Organize your code into separate files as explained in Section 2.4 of the notes. Once again, you’ll need to decide how arguments should be passed to the methods and operators. Declare methods to be constant, as appropriate. Declare methods to be inline, as appropriate. 1 Write (and submit) a test driver for your class. Make sure you test every method and operator. 2. Create a function print_double_spaced(cs) that takes a C string as argument and prints the characters of that string separated by a space. For example, the string hello world should be printed as h e l l o w o r l d No space should be printed before the first character of the string or after the last one. The function should print nothing when called on an empty string. Implement the function as efficiently as possible. Hint: Don’t use strlen because that would be inefficient. My code is the image provided below: #include #include using namespace std; class Song { private: string Title; string Artist; int Year; public: Song() : Title("invalid"), Artist("invalid"), Year(-1) {} Song(const string & Title) : Title(Title), Artist("unknown"), Year(-1) {} Song(const string & Title, const string & Artist, int Year) : Title(Title), Artist(Artist), Year(Year) {} bool equals(const Song &other) const { return Title == other.Title && Artist == other.Artist && Year == other.Year; } bool less_than(const Song &other) const { if (Title < other.Title) return true; else if (Title == other.Title) { if (Artist < other.Artist) return true; else if (Artist == other.Artist) { return Year < other.Year; } } return false; } const string & Title() const { return Title; } const string & Artist() const { return Artist; } int Year() const { return Year; } }; int main() { Song song1; Song song2("Title2"); Song song3("Title3", "Artist3", 2023); cout << song1.Title() << endl << song1.Artist() << endl << song1.Year() << endl; cout << endl; cout << song2.Title() << endl << song2.Artist() << endl << song2.Year() << endl; cout << endl; cout << song3.Title() << endl << song3.Artist() << endl << song3.Year() << endl; cout << endl; if (song1.equals(song2)) { cout << "Songs 1 and 2 are equal" << endl; } else { cout << "Songs 1 and 2 are not equal" << endl; } if (song2.equals(song3)) { cout << "Songs 2 and 3 are equal" << endl; } else { cout << " Songs 2 and 3 are not equal" << endl; } if (song1.equals(song3)) { cout << "Song 1 and 3 are equal" << endl; } else { cout << "Song 1 and 3 are not equal" << endl; } return0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Could you help me with this C++ code please:

Modify the class Song you created by doing the
following:
(a) 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 argument, the third one takes an integer.
(b) 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.
(c) Replace the equals method by an equality operator (==).
(d) Replace the less_than method by a less-than operator (<).
(e) Replace the print method by an output operator (<<).
(f) Replace the read method by an input operator (>>).
(g) Organize your code into separate files as explained in Section 2.4 of
the notes.
Once again, you’ll need to decide how arguments should be passed to the
methods and operators.
Declare methods to be constant, as appropriate. Declare methods to be
inline, as appropriate.
1
Write (and submit) a test driver for your class. Make sure you test every
method and operator.
2. Create a function print_double_spaced(cs) that takes a C
string as argument and prints the characters of that string separated by a
space. For example, the string hello world should be printed as
h e l l o w o r l d
No space should be printed before the first character of the string or after
the last one. The function should print nothing when called on an empty
string. Implement the function as efficiently as possible. Hint: Don’t use
strlen because that would be inefficient. 

My code is the image provided below:

#include <iostream>
#include <string>
using namespace std;

class Song {
private:
  string Title;
  string Artist;
  int Year;

public:
  Song() : Title("invalid"), Artist("invalid"), Year(-1) {}
  Song(const string & Title) : Title(Title), Artist("unknown"), Year(-1) {}
  Song(const string & Title, const string & Artist, int Year)
      : Title(Title), Artist(Artist), Year(Year) {}

  bool equals(const Song &other) const {
    return Title == other.Title && Artist == other.Artist && Year == other.Year;
  }
  bool less_than(const Song &other) const {
    if (Title < other.Title)
      return true;
    else if (Title == other.Title) {
      if (Artist < other.Artist)
        return true;
      else if (Artist == other.Artist) {
        return Year < other.Year;
      }
    }
    return false;
  }

  const string & Title() const { return Title; }
  const string & Artist() const { return Artist; }
  int Year() const { return Year; }
};


int main() {
  Song song1;
  Song song2("Title2");
  Song song3("Title3", "Artist3", 2023);
  cout << song1.Title() << endl << song1.Artist() << endl << song1.Year() << endl;
  cout << endl;
  cout << song2.Title() << endl << song2.Artist() << endl << song2.Year() << endl;
  cout << endl;
  cout << song3.Title() << endl << song3.Artist() << endl << song3.Year() << endl;
  cout << endl;

  if (song1.equals(song2)) {
    cout << "Songs 1 and 2 are equal" << endl;
  } else {
   cout << "Songs 1 and 2 are not equal" << endl;
  }

  if (song2.equals(song3)) {
    cout << "Songs 2 and 3 are equal" << endl;
  } else {
    cout << " Songs 2 and 3 are not equal" << endl;
}

if (song1.equals(song3)) {
    cout << "Song 1 and 3 are equal" << endl;
} else {
    cout << "Song 1 and 3 are not equal" << endl;
}

return0;

}

Expert Solution
Step 1

Here's the modified code with the requested changes:

Song.h:

 

#ifndef SONG_H
#define SONG_H

#include <iostream>
#include <string>

class Song {
private:
  std::string Title;
  std::string Artist;
  int Year;

public:
  Song() : Title("invalid"), Artist("invalid"), Year(-1) {}
  Song(const std::string &Title) : Title(Title), Artist("unknown"), Year(-1) {}
  Song(const std::string &Title, const std::string &Artist, int Year)
      : Title(Title), Artist(Artist), Year(Year) {}

  void set_title(const std::string &title) { Title = title; }
  void set_artist(const std::string &artist) { Artist = artist; }
  void set_year(int year) { Year = year; }
  void set(const std::string &title, const std::string &artist, int year) {
    Title = title;
    Artist = artist;
    Year = year;
  }

  bool operator==(const Song &other) const {
    return Title == other.Title && Artist == other.Artist && Year == other.Year;
  }

  bool operator<(const Song &other) const {
    if (Title < other.Title)
      return true;
    else if (Title == other.Title) {
      if (Artist < other.Artist)
        return true;
      else if (Artist == other.Artist) {
        return Year < other.Year;
      }
    }
    return false;
  }

  friend std::ostream &operator<<(std::ostream &out, const Song &song) {
    out << song.Title << " by " << song.Artist << " (" << song.Year << ")";
    return out;
  }

  friend std::istream &operator>>(std::istream &in, Song &song) {
    std::string title, artist;
    int year;
    in >> title >> artist >> year;
    song.set(title, artist, year);
    return in;
  }

  const std::string &get_title() const { return Title; }
  const std::string &get_artist() const { return Artist; }
  int get_year() const { return Year; }
};

#endif

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education