Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<conio.h>
  4. using namespace std;
  5.  
  6. string box[5]={"N","N","N","N","N"};
  7. int space=0;
  8.  
  9. void pop(){
  10.  
  11. if(space !=0){
  12. box[space]; space--;
  13. }else{ cout << "\n\n\tStack UnderFlow! You cannot remove any more books because it is already empty! Press any key to continue"; getch();}
  14.  
  15. }
  16.  
  17. void push(){
  18. space++;
  19.  
  20. if(space != 6){
  21. cout << "\n\n\tWhat is the name of the book? "; cin.ignore(); getline(cin,box[space-1]);
  22. }else{
  23. space--;
  24. cout << "\n\n\tStack OverFlow! You cannot add any more inside the box! Press any key to continue"; getch();
  25. }
  26. }
  27.  
  28. void print(){
  29.  
  30. if(box[0] == "N"){
  31. cout << "\n\n\tThe Box is empty at the momment";
  32. }else{
  33. for(int x = 0; x < space; x++){
  34. if(box[x] != "N"){ cout <<"\n\t" <<box[x]; }
  35. }
  36. }
  37. }
  38.  
  39. int main(){
  40. int c;
  41. cout << "\n\tArray Linked list version";
  42.  
  43. do{
  44. system("cls");
  45. cout<< "\n\n\tYou got a box that has a space for 5 books: \n";
  46. print();
  47. cout << "\n\n\tHere are your options \n\t[1] = add book \n\t[2]= remove book \n\t[Any number]= leave\n\n\t"; cin>>c;
  48. if(c == 1){ push(); }else
  49. if(c == 2 ){ pop(); }else{
  50. cout<<"\n\n\tGoodbye"; break;
  51. }
  52. }while(!0);
  53. getch();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement