Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: C++  |  size: 2.23 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void library::delete_book(unsigned int index)
  2. {
  3.  
  4.         int i=0;
  5.         vector<book>::iterator it;
  6.         it = booksObj.begin() + index -1;
  7.         cout << "index = " << index <<endl;
  8.  
  9.         for(;i!=get_num_books();i++)
  10.         cout << booksObj[i].get_bookTitle() <<endl;
  11.         cout << "---------------------\n";
  12.         if (booksObj.size() >= index) // warning
  13.                 booksObj.erase(booksObj.begin() +index-1); //error!
  14.         else                                              //this always delete the last element
  15.                 cout << "ERROR: Out of Bound Index\n";
  16.  
  17.         for(i=0;i!=get_num_books();i++)
  18.         cout << booksObj[i].get_bookTitle() <<endl;
  19.         cout << "---------------------\n";
  20.  
  21.  
  22. }
  23.  
  24.  
  25. main()
  26. {
  27. //....stuff
  28.  for( x=0 ; x!=libObj.get_num_cards() ;x++)
  29.                         if ( libObj.cardsObj[x].get_card_id() == card_removed )
  30.                                 {
  31.                                         if (libObj.cardsObj[x].get_checked_book () != 0 )
  32.                                            {
  33.                                                 cout << "Please return any books ";
  34.                                                 cout << "before removing this card"<<endl;
  35.                                                 libraryMainMenu(libObj);
  36.                                            }
  37.                                         libObj.delete_card(x);
  38.                                         cout << "The card was removed from the database\n";
  39.                                         libObj.updateDB();
  40.                                         libraryMainMenu(libObj);
  41.                                 }
  42.                         cout << "\ncard id number was not found\n";
  43.                         cout << "going back to the main menu\n";
  44.                         libraryMainMenu(libObj);
  45.           }
  46.  
  47.  
  48. //.... stuff
  49. }
  50.  
  51. /*
  52. OUTPUT
  53. ------
  54. index = 6
  55. The_Island
  56. The_dragorn_tatu
  57. The_Rapture
  58. The_bible
  59. quran
  60. Fifty_Shades_of_Grey //this is suppose to be removed
  61. Souls
  62. Broken_Katy
  63. Man_of_Luck
  64. The_Witch's_Legacy
  65. The_Edge_of_the_Wife
  66. ---------------------
  67. The_Island
  68. The_dragorn_tatu
  69. The_Rapture
  70. The_bible
  71. quran
  72. Fifty_Shades_of_Grey
  73. Souls
  74. Broken_Katy
  75. Man_of_Luck
  76. The_Witch's_Legacy
  77. ---------------------
  78.  
  79. **/