// demonstration of linked data. Model of a small public library // To Be Done: returning copies of books, removing patrons, editting data on file.... #include #include using namespace std; class Person{ public: string name; string address; Person(string n="Unknown", string a="no fixed abode"): name(n), address(a) {} }; class Patron : public Person{ public: Patron * next; Patron(string n="Unknown", string a="no fixed abode"): Person(n,a), next(NULL){} }; class Book{ public: string ISBN; string title; Book * next; Book(string i="0000000000", string t="unknown title"):ISBN(i), title(t), next(NULL){} }; class Copy{ public: Book * book; int copy; Copy * previous; Copy * next; Copy(Book *b, Copy * p): book(b), previous(p), next(NULL){ if(previous){ copy = previous->copy + 1; previous -> next = this; } else { copy=1; } } }; class Loan{ public: Copy * borrowed; Person * patron; Loan * next; Loan * previous; Loan( Loan * pr, Copy * b, Person * p ): borrowed(b), patron(p), next(NULL), previous(pr){ if(previous){ previous -> next = this; } } }; int main() { Patron me("Dick", "JBH341"); Book scansholm("0-201-72168", "C++ from the beginning"); Copy acopy(&scansholm, NULL); Loan aloan(NULL, &acopy, &me); cerr << (&aloan)->patron->name << endl; cerr << (&aloan)->borrowed->book->title << endl; }