I have taken a step back before implementing authors.
What I am going to do is input a string containing the author(s)
first middle last, first middle last and parse the string seperating it into a vector<string> authors.
but looking at my code I need to slow down and am having some very basic problems with my book class here is my revised code before implementing author(s).
Code:
#ifndef BOOK_H
#define BOOK_H
#include <iostream>
using namespace std;
#include <string>
#include <vector>
class Book{
friend ostream &operator<<(ostream &,const Book &);
friend istream &operator>>(istream &,const Book &);
public:
Book();
// constructor title,author,publisher,copy right,isbn,price
// used for string literals in constructor
Book(string,string="",string="",string="",string="",double=0.0);
string get_title() const {return title;}
string get_publisher() const {return publisher;}
string get_ISBN() const {return ISBN;}
string get_datecopyright() const {return datecopyright;}
double get_price() const {return price;};
void edit_book(Book &);
void set_title(string);
void set_authors(string);
void set_publisher(string);
void set_ISBN(string);
void set_datecopyright(string);
void set_price(double);
private:
string title;
// last,first,middle name
string publisher;
string datecopyright;
string ISBN;
int barcode;
double price;
};
#endif
i am getting ambigous errors with my istream operator can anyone help
Code:
#include <iostream>
#include <string>
using namespace std;
#include "book.h"
Book::Book(){
set_title("");
set_authors("");
set_publisher("");
set_ISBN("");
set_datecopyright("");
set_price(0.0);
}
// constructor title,author,publisher,ISBN,copy right,price
Book::Book(string ttitle,string tauthors,string tpublisher,string tISBN,string tcopyright,double tprice){
set_title(ttitle);
set_authors(tauthors);
set_publisher(tpublisher);
set_ISBN(tISBN);
set_datecopyright(tcopyright);
set_price(tprice);
}
void Book::set_title(string ttitle){
title=ttitle;
}
void Book::set_authors(string tauthors){
}
void Book::set_publisher(string tpublisher){
publisher=tpublisher;
}
void Book::set_ISBN(string tISBN){
ISBN=tISBN;
}
void Book::set_datecopyright(string tcopyright){
datecopyright=tcopyright;
}
void Book::set_price(double tprice){
price=tprice;
}
void edit_book(Book & tBook){
cout << tBook;
cin >> tBook;
cout << "Revised Input:\n";
cout << tBook;
}
istream & operator>>(istream &input,Book &tBook){
string ttitle,tauthors,tpublisher,tISBN,tcopyright;
double tprice;
cout << "Enter Title (required):";
input >> ttitle;
tBook.set_title(ttitle);
cout << "Enter Author(s)(in the form first middle(optional) last,next author):";
input >> tauthors;
tBook.set_authors(tauthors);
cout << "Enter Publisher:";
input >> tpublisher;
tBook.set_publisher(tpublisher);
cout << "Enter ISBN:";
input >> tISBN;
tBook.set_ISBN(tISBN);
cout << "Enter copy right year:";
input >> tcopyright;
tBook.set_datecopyright(tcopyright);
cout << "Enter price of book:";
input >> tprice;
tBook.set_price(tprice);
return input;
}
ostream &operator<<(ostream & output,Book & tBook){
output << "Title:"<<tBook.get_title()<<endl;
output << "Publsher:"<<tBook.get_publisher()<<endl;
output << "ISBN:"<<tBook.get_ISBN()<<endl;
output << "Copy Right Date:"<<tBook.get_datecopyright()<<endl;
output << "Price:"<<tBook.get_price()<<endl;
return output;
}
here is a simple test main
Code:
include <iostream>
#include <stdlib.h>
#include "book.h"
using std::cin;
int main(int argc, char *argv[])
{
Book Entry();
cin >> Entry;
Entry.edit_book(Entry);
//display main menu
//get user input display appropriat menu
//if query build queryset
system("PAUSE");
return 0;
}
Ooops I edited the post to include the author class instead of the book class again sorry.
BTW thanks for the help ignore this post as I started from scratch and solved the problem with the istream/ostream operator though I don't know what I did wrong originally. I'll post further questions in a new thread.