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 66 67 68 69 70 71 72 73 74 75 76 77
|
#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] = authors[MAX_AUTHORS];
this -> publisher = publisher;
this -> yearPublish = yearPublish;
this-> hardcover = hardcover;
this-> price = price;
this-> isbn = isbn;
this-> copies = copies;
this->next = nullptr;
}
void Book:: setTitle(string title){
this-> title = title;
}
string Book:: getTitle()const{
return title;
}
void Book:: setISBN(string isbn){
this-> isbn = isbn;
}
string Book::getISBN()const{
return isbn;
}
void Book::setNext(Book* next){
this-> next = next;
}
Book* Book:: getNext() const{
return next;
}
istream& operator >> (istream& is, Book& book){
string input;
int counter = 1;
while (counter==1 && !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;
getline(is, input);
counter++;
}
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;
}
|