I need help with my program. I have four errors with the ostream. It should be print my list of books. I know its something simple... I just can't figure it out!
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------------
class Book {
private:
string title, author, genre, pubyear, publisher;
public:
Book();
Book(const Book& b);
Book(string t, string a, string g, string py, string p);
// bool operator==(const Book& b);
// bool compare==(const Book& b);
string getTitle();
string getAuthor();
string getGenre();
string getPubYear();
string getPublisher();
void set(string a, string t, string g, string py, string p);
void setTitle(string t);
void setAuthor(string a);
void setGenre(string g);
void setPubYear(string py);
void setPublisher(string p);
friend class Node;
friend class List;
friend istream& operator>>(istream& is, Book& b);
friend ostream& operator<<(ostream& os, Book& b);
friend ostream& operator<<(ostream&, const List&);
};
//----------------------------------------------------------------------------
class Node {
Book data;
Node *next;
Node *prev;
public:
Node() : data(), next(NULL) { }
Node(Book b) : data(b), next(NULL) { }
Node(Book b, Node* n) : data(b), next(n) { }
Node(Book b, Node *n, Node *p) : data(b), next(n), prev(p) {}
Node *getNext(void) const { return next; }
Node *getPrev(void) const { return prev; }
Book getData(void) const { return data; }
void setData(Book b) { data = b; }
void setNext(Node* n) { next = n; }
void setPrev(Node* p) { prev = p; }
friend ostream& operator<<(ostream&, const List&);
friend class List;
friend class Book;
};
//-----------------------------------------------------------------------------
class List {
Node *start;
public:
List();
void push_front(Book);
void push_back(Book);
void pop_front(void);
void pop_back();
Node *find(Book);
void insert(Node *, Book);
friend class Book;
friend ostream& operator<<(ostream&, const List&);
};
//------------------------------------------------------------------------------
// END OF CLASSES
//
//------------------------------------------------------------------------------
Book::Book():title(" "), author(" "), genre(" "), pubyear(" "), publisher(" "){}
Book::Book(string a, string t, string g, string py, string p) : author(a), title(t), genre(g), pubyear(py), publisher(p){}
Book::Book(const Book& b):title(b.title), author(b.author), genre(b.genre), pubyear(b.pubyear), publisher(b.publisher){}
string Book::getTitle(){
return title;}
string Book::getAuthor(){
return author;}
string Book::getGenre(){
return genre;}
string Book::getPubYear(){
return pubyear;}
string Book::getPublisher(){
return publisher;}
void Book::set(string a, string t, string g, string py, string p) {author=a, title=t, genre=g, pubyear=py, publisher=p;}
void Book::setTitle(string t){
title=t;}
void Book::setAuthor(string a){
author=a;}
void Book::setGenre(string g){
genre=g;}
void Book::setPubYear(string py){
pubyear=py;}
void Book::setPublisher(string p){
publisher=p;}
istream& operator>>(istream& is, Book& b){
string t, a, g, py, p;
cout << endl << "Enter the following information for a book:" << endl;
cout << "Title: ";
getline(cin,t);
b.setTitle(t);
cout << "Author: ";
getline(cin,a);
b.setAuthor(a);
cout << "Genre: ";
getline(cin,g);
b.setGenre(g);
cout << "Publisher: ";
getline(cin,p);
b.setPublisher(p);
cout << "Publication Year: ";
getline(cin,py);
b.setPubYear(py);
cout << endl;
return is;
}
/*bool Book::operator ==(const Book& b)
{
if(author==b.author &&
title==b.title &&
genre==b.genre &&
pubyear==b.pubyear &&
publisher==b.publisher)
{
return true;
}
else
{
return false;
}
}*/
/*bool compare::operator==(const Book b) {
if(author==b.author &&
title==b.title &&
genre==b.genre &&
pubyear==b.pubyear &&
publisher==b.publisher)
{
return true;
}
else
{
return false;
}
*/
ostream& operator<<(ostream& os, Book& b){
os << "Title: " << b.title << endl;
os << "Author: " << b.author << endl;
os << "Genre: " << b.genre << endl;
os << "Publisher: " << b.publisher << endl;
os << "Publication Year: " << b.pubyear << endl << endl;
return os;
}
//------------------------------------------------------------------------------
/*Node *List::find(Book b) {
Node *temp = start;
while (temp) {
if(temp.compare(b);
return temp;
temp = temp->getNext();
}
return 0;
}*/
//------------------------------------------------------------------------------
/*void List::insert(Node *ptr, Book b) {
Node *insertNode = new Node(b,ptr->getNext());
ptr->setNext(insertNode);
return;
}*/
//------------------------------------------------------------------------------
ostream& operator<<(ostream& os, const List& l) {
os << "< ";
Node *temp = l.start;
temp->getAuthor();
while (temp) {
os << temp->getData() << " ";
os << temp->getAuthor();
temp = temp->getNext();
}
os << ">";
return os;
}
List::List() : start(NULL) { }
void List::push_front(Book b) {
Node *newone = new Node(b,start);
start = newone;
return;
}
void List::push_back(Book) {
Node *newone = new Node();
if (start == NULL)
start = newone;
else {
Node *temp = start;
while (temp->getNext() != NULL)
temp = temp->getNext();
temp->setNext(newone);
}
return;
}
void List::pop_front(void){
if (start != NULL) {
Node *temp;
temp = start->getNext();
delete start; // free first element
start = temp;
}
}
void List::pop_back(){
if (start != NULL) {
Node *lag, *temp = start;
while(temp->getNext() != NULL) {
lag = temp;
temp = temp->getNext();
}
delete temp;
lag->setNext(NULL);
}
}
//------------------------------------------------------------------------------
int main( ) {
//------------------------------------------------------------------------------
Book b1, b2, b3("Tony Gaddis", "Starting out with Python", "CS", "2009", "Pearson-Addision-Wesley");
b1.set("John Zelle", "Python Programming", "CS", "2004", "Franklin, Beedle & Associates" );
b2.setAuthor("Glenn Brookshear");
b2.setTitle("Computer Science: an Overview");
b2.setGenre("CS");
b2.setPubYear("2009");
b2.setPublisher("Pearson-Addision-Wesley");
Book b4(b2);
cout << b4.getAuthor() << " " << b4.getTitle() << " " << b4.getGenre() << " " << b4.getPubYear()<< endl;
Book b5;
cin >> b5;
cout << b1 << b2 << b3 << b4 << b5;
//------------------------------------------------------------------------------
List a;
a.push_back(b1);
a.push_back(b2);
a.push_back(b3);
/*a.push_back(20);
a.push_back(30);
a.push_back(40);
a.push_back(50);*/
cout << a << endl;
//------------------------------------------------------------------------------
// Node *temp;
// temp = a.find(b2);
// a.insert(temp, b3);
/*
temp = a.find(30);
a.insert(temp, 35);
temp = a.find(50);
a.insert(temp, 1);*/
cout << a << endl;
/*
//------------------------------------------------------------------------------
a.pop_front();
cout << "After pop_front" << endl;
cout << a << endl;
//------------------------------------------------------------------------------
a.pop_back();
cout << "After pop_back" << endl;
cout << a << endl;
*/
int x;
cin >> x;
}