Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cctype>
  4. #include "invmenu.h"
  5. #include "globals.h"
  6. #include "bookinfo.h"
  7. using namespace std;
  8.  
  9. void setTitle();
  10. void showTitle();
  11. int findEmptySlot(); // function prototypes
  12.  
  13. BookData Collection[20];
  14.  
  15. void structtest()
  16. {
  17.  
  18. const int SIZE = 80;
  19. char buffer[SIZE];
  20. int choice;
  21.  
  22. do
  23. {
  24. cout << " Serendipity Bookssellsers " << endl;
  25. cout << " Inventory Database " << endl;
  26. cout << " " << endl;
  27. cout << " 1. Set Title " << endl;
  28. cout << " 2. Show Title " << endl;
  29. cout << " Enter Your Choice: ";
  30.  
  31. cin.getline(buffer,SIZE);
  32. choice = atoi(buffer);
  33.  
  34. switch(choice)
  35. {
  36. case 1:
  37. setTitle();
  38. break;
  39. case 2:
  40. showTitle();
  41. break;
  42. case 3:
  43. cout << "Returning to Main Menu!" << endl;
  44. break;
  45. default:
  46. cout << "Please enter a number in the range 1-5." << endl;
  47. }
  48. }while(choice != 3);
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. int findEmptySlot()
  56. {
  57. int index = -1;
  58. for(int i = 0; i < NUM_BOOKS; i++)
  59. {
  60. if(Collection[20].bookTitle == '\0')
  61. {
  62. index = i;
  63. break;
  64. }
  65. }
  66.  
  67. return 1;
  68.  
  69. }
  70.  
  71.  
  72. void setTitle()
  73. {
  74. const int BUFFER_SIZE = 80;
  75. char buffer[BUFFER_SIZE];
  76. int index = findEmptySlot();
  77. if(index != -1)
  78. {
  79. cout << "Enter the following Information to add a book" << endl;
  80. cout << "Book title : ";
  81. cin.getline(Collection[index].bookTitle, BUFFER_SIZE);
  82. }
  83. }
  84.  
  85. void showTitle()
  86. {
  87. cout << Collection[20].bookTitle;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement