// BIB_ITEM.CPP const char Blank[] = "--------"; char temp[ SSize ]; const char NewLine = '\n'; // ITEM ///////////////////////////////////////////////////////////////////// int Item::Count = 0; int Item::Total = 0; Item::Item() // VIRTUAL CONSTRUCTOR { Next = NULL; ++Count; ++Total; } Item::Item( char *, char * ) // VIRTUAL CONSTRUCTOR { cout << "\n\t ERROR ERROR -- ITEM::ITEM( CHAR *A, CHAR *T ) -- \n"; } inline Item::~Item() // VIRTUAL DESTRUCTOR { --Total; } inline int Item::Get_Total( void ) const { return ( Total ); } inline char *Item::Get_Author( void ) { cout << "\n\t ERROR ERROR -- WRITE A GET_AUTHOR FUNCTION -- \n"; return ( NULL ); } inline char *Item::Get_Title( void ) { cout << "\n\t ERROR ERROR -- WRITE A GET_TITLE FUNCTION -- \n"; return ( NULL ); } inline Item *Item::Get_Next( void ) { cout << "\n\t ERROR ERROR -- WRITE A GET_NEXT FUNCTION -- \n"; return ( NULL ); } void Item::Print( void ) const { cout << "\n\t ERROR ERROR -- WRITE A PRINT FUNCTION -- \n"; } void Item::Get_Data( void ) { cout << "\n\t ERROR ERROR -- WRITE A GET_DATA FUNCTION -- \n"; } // BOOK ///////////////////////////////////////////////////////////////////// int Book::Count = 0; int Book::Total = 0; Book::Book( char *A, char *T, char *C, char *P, char *PC ) // CONSTRUCTOR { int i; char c; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, A ); strcpy( Title, T ); strcpy( Copyright, C ); strcpy( Publisher, P ); strcpy( Pub_City , PC ); } Book::Book( char *A, char *T ) // CONSTRUCTOR { int i; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, NULL ); strcpy( Title, NULL ); strcpy( Copyright, Blank ); strcpy( Publisher, Blank ); strcpy( Pub_City , Blank ); strcpy( temp, A ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, T ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); Get_Data(); } inline Book::~Book() // DESTRUCTOR { --Total; } inline char *Book::Get_Author( void ) { return ( Author ); } inline char *Book::Get_Title( void ) { return ( Title ); } inline int Book::Get_Total( void ) const { return ( Total ); } /* inline Book *Book::Get_Next( void ) { return ( Next ); } */ void Book::Print( void ) const { cout // << "\n\t Book Total: " << Total // << "\n\t ID : " << ID << "\n\t Author : " << Author << "\n\t Title : " << Title << "\n\t Copyright : " << Copyright << "\n\t Publisher : " << Publisher << "\n\t City : " << Pub_City << "\n"; } void Book::Get_Data( void ) { int i; char c; cout << " \n\t Enter Book Copyright ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Copyright, temp ); cin.get( c ); cout << " \n\t Enter Book Publisher ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Publisher, temp ); cin.get( c ); cout << " \n\t Enter Book Publisher City ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Pub_City, temp ); cin.get( c ); } // MAG ////////////////////////////////////////////////////////////////////// int Mag::Count = 0; int Mag::Total = 0; Mag::Mag( char *A, char *T, char *MT, char *C, char *V, char *N, char *P ) // CONSTRUCTOR { int i; char c; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, A ); strcpy( Title, T ); strcpy( Mag_Title, MT ); strcpy( Copyright, C ); strcpy( Volume, V ); strcpy( Number , N ); strcpy( Pages, P ); } Mag::Mag( char *A, char *T ) // CONSTRUCTOR { int i; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, NULL ); strcpy( Title, NULL ); strcpy( Mag_Title, Blank ); strcpy( Copyright, Blank ); strcpy( Volume, Blank ); strcpy( Number , Blank ); strcpy( Pages, Blank ); strcpy( temp, A ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, T ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); Get_Data(); } inline Mag::~Mag() // DESTRUCTOR { --Total; } inline char *Mag::Get_Author( void ) { return ( Author ); } inline char *Mag::Get_Title( void ) { return ( Title ); } inline int Mag::Get_Total( void ) const { return ( Total ); } /* inline Item *Mag::Get_Next( void ) { return ( Next ); } */ void Mag::Print( void ) const { cout // << "\n\t Mag Total : " << Total // << "\n\t ID : " << ID << "\n\t Author : " << Author << "\n\t Title : " << Title << "\n\t Mag Title : " << Mag_Title << "\n\t Copyright : " << Copyright << "\n\t Volume : " << Volume << "\n\t Number : " << Number << "\n\t Pages : " << Pages << "\n"; } void Mag::Get_Data( void ) { int i; char c; cout << " \n\t Enter Mag Title ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Mag_Title, temp ); cin.get( c ); cout << " \n\t Enter Mag Copyright ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Copyright, temp ); cin.get( c ); cout << " \n\t Enter Mag Volume ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Volume, temp ); cin.get( c ); cout << " \n\t Enter Mag Number ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Number, temp ); cin.get( c ); cout << " \n\t Enter Mag Pages ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Pages, temp ); cin.get( c ); } // MicroFilm ////////////////////////////////////////////////////////////////////// int MicroFilm::Count = 0; int MicroFilm::Total = 0; MicroFilm::MicroFilm( char *A, char *T, char *C, char *V, char *N, char *F ) { int i; char c; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, A ); strcpy( Title, T ); strcpy( Copyright, C ); strcpy( Volume, V ); strcpy( Number , N ); strcpy( Footage, F ); } MicroFilm::MicroFilm( char *A, char *T ) // CONSTRUCTOR { int i; Next = NULL; ++Count; ++Total; ID = Count; strcpy( Author, NULL ); strcpy( Title, NULL ); strcpy( Copyright, Blank ); strcpy( Volume, Blank ); strcpy( Number , Blank ); strcpy( Footage, Blank ); strcpy( temp, A ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, T ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); Get_Data(); } inline MicroFilm::~MicroFilm() // DESTRUCTOR { --Total; } inline char *MicroFilm::Get_Author( void ) { return ( Author ); } inline char *MicroFilm::Get_Title( void ) { return ( Title ); } inline int MicroFilm::Get_Total( void ) const { return ( Total ); } /* inline Item *MicroFilm::Get_Next( void ) { return ( Next ); } */ void MicroFilm::Print( void ) const { cout // << "\n\t MicroFilm Total : " << Total // << "\n\t ID : " << ID << "\n\t Author : " << Author << "\n\t Title : " << Title << "\n\t Copyright : " << Copyright << "\n\t Volume : " << Volume << "\n\t Number : " << Number << "\n\t Footage : " << Footage << "\n"; } void MicroFilm::Get_Data( void ) { int i; char c; cout << " \n\t Enter MicroFilm Copyright ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Copyright, temp ); cin.get( c ); cout << " \n\t Enter Microfilm Volume ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Volume, temp ); cin.get( c ); cout << " \n\t Enter Microfilm Number ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Number, temp ); cin.get( c ); cout << " \n\t Enter Microfilm Footage ==>"; strcpy( temp, NULL ); cin.get( temp, SSize, NewLine ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); if( strcmp(temp, "") != 0 ) strcpy( Footage, temp ); cin.get( c ); } // ITEMS //////////////////////////////////////////////////////////////////// Items::Items( char *IType ) // CONSTRUCTOR { strcpy( Type, IType ); Head_List = NULL; Next_Item = NULL; } inline Items::~Items ( void ) // DESTRUCTOR { ; } void Items::Print( void ) const { cout << "\nBib. Type: " << Type << " Total: "; if( Head_List ) cout << Head_List->Get_Total() << "\n"; else cout << 0 << "\n"; } // BIB_ITEM ///////////////////////////////////////////////////////////////// Bib_Item::Bib_Item( void ) // CONSTRUCTOR { Head = NULL; Sort1 = NULL; Sort2 = NULL; } inline Bib_Item::~Bib_Item( void ) // DESTRUCTOR { ; } void Bib_Item::Print( void ) const { Items *ptr = Head; while( ptr ) { ptr->Print(); ptr = ptr->Next_Item; } } void Bib_Item::Print( char *Type ) const { int i; strcpy( temp, Type ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Type, temp ); Items *ptr = Head; while( ptr && strcmp(ptr->Type, Type) != 0 ) ptr = ptr->Next_Item; if( ptr ) { ptr->Print(); Item *ptr2; ptr2 = ptr->Head_List; while( ptr2 ) { cout << "\n\t Author : " << ptr2->Get_Author() << "\n\t Title : " << ptr2->Get_Title() << "\n"; ptr2 = ptr2->Next; } } } void Bib_Item::Print( char *Type, char *Author, char *Title ) { int i; strcpy( temp, Type ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Type, temp ); strcpy( temp, Author ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, Title ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); Item *p; p = Find( Type, Author, Title ); if( p ) { ptr->Print(); p->Print(); } } Item *Bib_Item::Find( char *Type, char *Author, char *Title ) { ptr = Head; ptr2 = NULL; found1 = 0x0; Sort1 = NULL; while( ptr && !found1 ) { if( strcmp(Type, ptr->Type) > 0 ) Sort1 = ptr; if( strcmp(Type, ptr->Type) == 0 ) found1 = 0xFF; else ptr = ptr->Next_Item; } if( found1 ) { int found = 0x00; ptr2 = ptr->Head_List; Sort2 = NULL; while( ptr2 && ! found ) { if( strcmp(Author, ptr2->Get_Author()) > 0 ) Sort2 = ptr2; if( strcmp(ptr2->Get_Author(), Author) == 0 && strcmp(ptr2->Get_Title(), Title) == 0 ) found = 0xFF; else ptr2 = ptr2->Next; } } return( ptr2 ); } Item *Bib_Item::Add( char *Type, char *Author, char *Title ) { int i; strcpy( temp, Type ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Type, temp ); strcpy( temp, Author ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, Title ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); if( ! Find( Type, Author, Title ) ) { Item *temp; if( strcmp(Type, "BOOK") == 0 ) temp = new Book( Author, Title ); else if( strcmp(Type, "MAG") == 0 ) temp = new Mag( Author, Title ); else if( strcmp(Type, "MICROFILM") == 0 ) temp = new MicroFilm( Author, Title ); else { cout << "\n ERROR - NON DEFINED ==>" << Type << "<== EXITING ADD ! \n"; return( NULL ); } if( ! Head ) { Head = new Items( Type ); Head->Head_List = temp; } else if( found1 ) { if( Sort2 ) { temp->Next = Sort2->Next; Sort2->Next = temp; } else { temp->Next = ptr->Head_List; ptr->Head_List = temp; } } else { Items *temps; temps = new Items( Type ); if( Sort1 ) { temps->Next_Item = Sort1->Next_Item; Sort1->Next_Item = temps; // temps->Head_List = temp; } else { temps->Head_List = temp; temps->Next_Item = Head; Head = temps; } temps->Head_List = temp; } return( temp ); } else { cout << "\n ERROR ==>" << Type << " " << Author << " " << Title << "<== NOT ADDED ! \n"; return( NULL ); } } int Bib_Item::Delete( char *Type, char *Author, char *Title ) { Item *p; int i; strcpy( temp, Type ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Type, temp ); strcpy( temp, Author ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Author, temp ); strcpy( temp, Title ); for( i=0; i < SSize; i++ ) temp[i] = toupper( temp[i] ); strcpy( Title, temp ); p = Find( Type, Author, Title ); if( p ) { if( p == ptr->Head_List ) { ptr2 = p->Next; ptr->Head_List = ptr2; } else { ptr2 = ptr->Head_List; while( ptr2->Next != p ) ptr2= ptr2->Next; ptr2->Next = p->Next; } if( strcmp(ptr->Type, "BOOK") == 0 ) delete (Book *) p; else if( strcmp(ptr->Type, "MAG") == 0 ) delete (Mag *) p; else if( strcmp(ptr->Type, "MICROFILM") == 0 ) delete (MicroFilm *) p; return( 1 ); } else { cout << "\n ERROR ==>" << Type << " " << Author << " " << Title << "<== NOT DELETED ! \n"; return( 0 ); } } void Loader( Bib_Item *B ) { B->Head = new Items( "BOOK" ); B->Head->Head_List = new Book( "LOUIS GUZIK", "MY FIRST BOOK", "1991", "1st Pubisher", "Boston" ); B->Head->Head_List->Next = new Book( "LOUIS GUZIK", "MY SECOND BOOK", "1992", "1st Pubisher", "Boston" ); B->Head->Head_List->Next->Next = new Book( "JOHN SMITH", "JOHN'S BOOK", "1993", "1st Pubisher", "Boston" ); B->Head->Next_Item = new Items( "MAG" ); B->Head->Next_Item->Head_List = new Mag( "KATHY DAY", "FIRST MAG", "WOMAN'S WORLD", "1981", "One", "Two", "55" ); B->Head->Next_Item->Head_List->Next = new Mag( "LOUIS GUZIK", "SECOND MAG", "OUR WORLD", "1982", "Six", "Ten", "66" ); B->Head->Next_Item->Head_List->Next->Next = new Mag( "PETER JONES", "THIRD MAG", "Today", "1983", "3", "11", "77" ); B->Head->Next_Item->Next_Item = new Items( "MICROFILM" ); B->Head->Next_Item->Next_Item->Head_List = new MicroFilm( "ME", "FIRST FILM", "1981", "One", "Two", "777" ); B->Head->Next_Item->Next_Item->Head_List->Next = new MicroFilm( "THEM", "SECOND FILM", "1982", "Six", "Ten", "2001" ); B->Head->Next_Item->Next_Item->Head_List->Next->Next = new MicroFilm( "YOU", "THIRD FILM", "1983", "3", "11", "2010" ); } // BIB_ITEM.CPP // END //