[/#ifndef BOOK_H
#define BOOK_H
#include <iostream>
#include <string>
using namespace std;
class Book {
/**
* @param is the input stream
* @param book the book object to be filled
* @return the input stream
*/
friend istream& operator >> (istream& is, Book& book);
/**
* @param os the output stream
* @param book the book object reference * @return the output stream
*/
friend ostream& operator << (ostream& os, const Book& book);
public:
static const int MAX_AUTHORS = 35;
Book();
Book(string title_, string authors_[], int authorCount_, string publisher_,
short yearPublish_, bool hardcover_, float price_,
string isbn_, long copies_);
void setTitle(string title_); string getTitle();
void setAuthors (string authors_[]); string getAuthors();
void setAuthorCount(int authorCount_); int getAuthorCount();
void setPublisher(string publisher_); string getPublisher();
void setIsbn(string isbn_); string getIsbn();
void setHardcover(boolean hardcover_); boolean getHardcover();
void setPrice(float price_); float getPrice();
void setYearPublish(short yearPublish_); short getYearPublish();
void setCopies(long copies_); long getCopies();
private:
string title;
string authors[Book::MAX_AUTHORS];
int authorCount;
string publisher;
short yearPublish;
bool hardcover;
float price;
string isbn;
long copies;
};
#endif /* BOOK_H */
// @file Warehouse.h
#ifndef WAREHOUSE_H
#define WAREHOUSE_H
#include <iostream>
#include <string>
#include "Book.h"
using namespace std;
clss Warehouse {
/**
* @param is the input stream
* @param warehouse the warehouse object reference
* @return the input stream
*/
friend istream& operator >> (istream& is, Warehouse& warehouse);
/**
* @param os the output stream
* @param warehouse the warehouse object reference
* @return the output stream
*/
friend ostream& operator << (ostream& os, const Warehouse& warehouse);
public:
static const int MAX_BOOKS = 35;
Warehouse();
/**
* @param isbn the ISBN number to search for
* @param book reference to the matched book object, if found
* @return true if found.
*/
bool find (string isbn, Book& book) const;
/**
* Prints the inventory of the Warehouse (i.e. list all the books)
*/
void list () const;
private: /* extra credit */
void sort_();
private:
Book books[Warehouse::MAX_BOOKS];
int bookCount;
};
#endif /* WAREHOUSE_H */]
I just felt stuck because I did give it a try. Following is the implementation I tried for Book.cpp.
However, I wanted to know how to make this work without using an array if there are more than 1 book that is going to be read from the file.
[/#include "Book.h"
#include <string>
using namespace std;
static const int MAX_BOOKS = 35;
static const int MAX_AUTHORS = 20;
The thing is, it would read a file and store the books.
If the >> operator only read the first book from a file of books, how would I be able to read the next book?
C++ Network Programming – Volume 1
2
Douglas C. Schmidt
Stephen D. Huston
Addison-Wesley
2002
0
35.99
0-201-60464-7
236
Programming Ruby
2
David Thomas
Andrew Hunt
Addison-Wesley
2001
0
42.95
0-201-71089-7
123
Problem Solving with C++ - The Object of Programming
1
Walter Savitch
Addison Wesley Longman, Inc.
2001
0
74.00
0-201-70390-4
325
This is my book.dat
Thank you so much for the help, I'm just really confused