Can you help me with a C++ program: To the class Song you created previously (included below) add functions that perform conversions between songs and strings. More precisely, create a function to_string(s) that takes a song as argument and returns a string that contains three lines with the song data. For example, the 2019 song September Blues by Quantic should convert to the following string: September Blues\nQuantic\n2019\n And create a function to_Song(s) that takes a string as argument and returns a Song object. The string argument is assumed to contain three lines with valid song data, as shown above. Use string streams #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) {}   void set_title(const string &title) { Title = title; }   void set_artist(const string &artist) { Artist = artist; }   void set_year(int year) { Year = year; }   void set(const string &title, const 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; } };

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question

Can you help me with a C++ program:

To the class Song you created previously (included below)
add functions that perform conversions between songs and strings. More
precisely, create a function to_string(s) that takes a song as argument
and returns a string that contains three lines with the song data. For example, the 2019 song September Blues by Quantic should convert to the
following string:
September Blues\nQuantic\n2019\n
And create a function to_Song(s) that takes a string as argument and
returns a Song object. The string argument is assumed to contain three
lines with valid song data, as shown above.
Use string streams

#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) {}
  void set_title(const string &title) { Title = title; }
  void set_artist(const string &artist) { Artist = artist; }
  void set_year(int year) { Year = year; }
  void set(const string &title, const 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; }
};

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Types of Function
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning