1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include "Book.h"
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
Book :: Book() {}
Book :: Book (string title, string authors[], int authorCount, string publisher, short yearPublish, bool hardcover, float price, string isbn, long copies){
this->title_ = title;
this->authorCount_ = authorCount;
this-> authors_[MAX_AUTHORS-1]=authors[MAX_AUTHORS];
this->publisher_ = publisher;
this->yearPublish_ = yearPublish;
this->hardcover_ = hardcover;
this->price_ = price;
this->isbn_ = isbn;
this->copies_= copies;
}
void Book::setTitle(string title){
this->title_=title;
}
string Book::getTitle()const{
return title_;
}
void Book:: setIsbn(string isbn){
isbn_ = isbn;
}
string Book::getIsbn()const {
return isbn_;
}
istream& operator >> (istream& is, Book& book){
string input;
while(!is.eof()){
getline(is, book.title_);
getline(is, input);
book.authorCount_ = atoi(input.c_str());
for (int i=0;i<book.authorCount_;i++){
getline(is, book.authors_[i]);
}
getline(is, book.publisher_);
is >> book.yearPublish_;
is >> book.hardcover_;
is >> book.price_;
is >> book.isbn_;
is >> book.copies_;
getline(is, input);
}
return is;
}
ostream& operator << (ostream& os, const Book& book){
os<< "Title: " << book.title_ << endl;
for (int i=0; i<book.authorCount_; i++){
os<< "Authors: " << book.authors_[i] << endl;
}
os<< "Publisher: " << book.publisher_ << endl;
os<< "Year Published: " << book.yearPublish_ << endl;
os<<"Cover: ";
if (book.hardcover_ ==0) os << "Paperback" << endl;
else if (book.hardcover_==1) os << "Hardcover" << endl;
os<< "Price: $" << book.price_ << endl;
os<< "ISBN: " << book.isbn_ << endl;
os<<"Copies: " << book.copies_ << endl<< endl;
return os;
}
|