#include #include using namespace std; void showBooks(stack books) { if(!books.empty()) { cout << "\n\tBooks in the stack:" << endl; while(!books.empty()) { cout << "\t" << books.top() << endl; books.pop(); } } else { cout << "\n\tEmpty stack" << endl; } } int main() { stack books; int opt; string name; do { cout << "\nWhat do you want to do?" << endl; cout << "1 - Add new book" << endl; cout << "2 - Remove a book from the stack" << endl; cout << "3 - Show stack size" << endl; cout << "4 - Show stack" << endl; cout << "5 - Exit" << endl; cout << ">>> "; cin >> opt; switch(opt) { case 1: cin.get(); cout << "\nName: "; getline(cin, name); books.push(name); break; case 2: if(!books.empty()) { cout << "\n\tBook Removed: " << books.top() << endl; books.pop(); } break; case 3: cout << "\n\tSize: " << books.size() << endl; break; case 4: showBooks(books); break; case 5: break; default: cout << "\n\tUnknown option" << endl; break; } } while(opt != 5); return 0; }