#include #include #include //for class stack #include //for class string using namespace std; void stackOfInts(); //function declarations void stackOfStructs(); int main() { stackOfInts(); cout << "\n"; //Skip a line. stackOfStructs(); return EXIT_SUCCESS; } void stackOfInts() { stack s; //Born empty, but capable of holding ints. //The full name of this data type is std::stack s.push(10); s.push(20); s.push(30); cout << s.top() << "\n"; //Output the most recently pushed it. s.pop(); //Remove the most recently pushed item. cout << s.top() << "\n"; s.pop(); cout << s.top() << "\n"; s.pop(); } //s is automatically destructed when we hit this closing curly brace. void stackOfStructs() { struct person { string firstname; string lastname; }; const person a[] { //an array of three structs {"George", "Washington"}, {"John", "Adams"}, {"Thomas", "Jefferson"} }; stack s; //Born empty, but capable of holding persons. for (const auto& p: a) { //Push the 3 persons onto stack s. s.push(p); } while (!s.empty()) { //Keep popping stack s until it's empty. const person p {s.top()}; s.pop(); cout << p.firstname << " " << p.lastname << "\n"; } } //s is automatically destructed when we hit this closing curly brace.