This is the code I currently have. As you can see, its got a long way to go. What I need to do is be able to save and load the private data in the Book and Patron objects in such a way that I can access any given record without reading the whole thing. Strings have to be converted to old style C strings so that the Book and Patron records are all of fixed length so they can be saved in direct access files.
My current approach is bad (copying to char arrays w/o null characters (haven't figured that one out yet), filling unused cells with special characters, use sentinel characters to delimit the names and numbers, then, when loading, read different parts of the stream into different variables and so on. I don't like it at all. I know that there is a (much) better way. I missed that class though. So, I could use some guidance. What's the best way to do this?
Thanks for your time.
void Library::saveBooks(string save)
ofstream osavefile ( "Books.sav" );
for(int i = 1; i<bidnumber; i++)
unsigned long loanedto = 1000000000;
// Added to borrower ID to make it a fixed length
// number in the file. substracted after reading.
if (LOB[i].getTitle() != "rumuration")
// rumuration is returned if a book ID is unused.(book deleted previously)
// strcpy is no good. Whole point of converting is making each
// data structure take the same size on file for direct access.
loanedto = 1000000000 + LOB[i].getBorrower();
// even if BookID is unused, some padding should
// be written to file for random access to work, right?
This is what Book and Patron objects look like (Patron inherits from Person which is also included).
// Sacrifice goat and pray for miracle.
//Removed bunch of accessor and mutator functions
unsigned long idNumber; //unique number for this book
unsigned long checkedOutByPatronID ; //will be NULL if the book is available
#define MAX_BOOKS 20
class Patron : public Person
//Bunch of functions
unsigned long idNumber; //unique number for this patron
unsigned long hasCheckedOutBookID[MAX_BOOKS];
unsigned short numberOfBooksCheckedOut;
void editName(string s);