Question: Given a Book class with string data members title and author. Overload the < < operator for the Book class. To do this declare and

Given a Book class with string data members title and author. Overload the << operator for the Book class.
To do this declare and implement a friend function that
returns a reference to an ostream object;
accepts a reference to an ostream object and a constant reference to a Book object.
This function should send the string 'Title: "title", Author: "author"' to the ostream, replacing "title" and "author" with the actual title and author of the book.
For instance, if the book has title="C++ Primer" and author="Lippman", << would send 'Title: "C++ Primer", Author: "Lippman"' to the ostream object.
#include
using namespace std;
class Book {
private:
string title, author;
public:
Book(string title, string author): title(title), author(author){};
// Your code here
};

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 Programming Questions!