Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- using namespace std;
- string box[5]={"N","N","N","N","N"};
- int space=0;
- void pop(){
- if(space !=0){
- box[space]; space--;
- }else{ cout << "\n\n\tStack UnderFlow! You cannot remove any more books because it is already empty! Press any key to continue"; getch();}
- }
- void push(){
- space++;
- if(space != 6){
- cout << "\n\n\tWhat is the name of the book? "; cin.ignore(); getline(cin,box[space-1]);
- }else{
- space--;
- cout << "\n\n\tStack OverFlow! You cannot add any more inside the box! Press any key to continue"; getch();
- }
- }
- void print(){
- if(box[0] == "N"){
- cout << "\n\n\tThe Box is empty at the momment";
- }else{
- for(int x = 0; x < space; x++){
- if(box[x] != "N"){ cout <<"\n\t" <<box[x]; }
- }
- }
- }
- int main(){
- int c;
- cout << "\n\tArray Linked list version";
- do{
- system("cls");
- cout<< "\n\n\tYou got a box that has a space for 5 books: \n";
- print();
- 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;
- if(c == 1){ push(); }else
- if(c == 2 ){ pop(); }else{
- cout<<"\n\n\tGoodbye"; break;
- }
- }while(!0);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement