
Untitled
By: a guest on
May 5th, 2012 | syntax:
C++ | size: 2.23 KB | hits: 13 | expires: Never
void library::delete_book(unsigned int index)
{
int i=0;
vector<book>::iterator it;
it = booksObj.begin() + index -1;
cout << "index = " << index <<endl;
for(;i!=get_num_books();i++)
cout << booksObj[i].get_bookTitle() <<endl;
cout << "---------------------\n";
if (booksObj.size() >= index) // warning
booksObj.erase(booksObj.begin() +index-1); //error!
else //this always delete the last element
cout << "ERROR: Out of Bound Index\n";
for(i=0;i!=get_num_books();i++)
cout << booksObj[i].get_bookTitle() <<endl;
cout << "---------------------\n";
}
main()
{
//....stuff
for( x=0 ; x!=libObj.get_num_cards() ;x++)
if ( libObj.cardsObj[x].get_card_id() == card_removed )
{
if (libObj.cardsObj[x].get_checked_book () != 0 )
{
cout << "Please return any books ";
cout << "before removing this card"<<endl;
libraryMainMenu(libObj);
}
libObj.delete_card(x);
cout << "The card was removed from the database\n";
libObj.updateDB();
libraryMainMenu(libObj);
}
cout << "\ncard id number was not found\n";
cout << "going back to the main menu\n";
libraryMainMenu(libObj);
}
//.... stuff
}
/*
OUTPUT
------
index = 6
The_Island
The_dragorn_tatu
The_Rapture
The_bible
quran
Fifty_Shades_of_Grey //this is suppose to be removed
Souls
Broken_Katy
Man_of_Luck
The_Witch's_Legacy
The_Edge_of_the_Wife
---------------------
The_Island
The_dragorn_tatu
The_Rapture
The_bible
quran
Fifty_Shades_of_Grey
Souls
Broken_Katy
Man_of_Luck
The_Witch's_Legacy
---------------------
**/