#include <iostream>
#include <cstdlib>
#include <string>   //for class string
using namespace std;

//sp (the "stack pointer") is the number of people currently employed.
//For example, if sp is 3, then their names are in a[0], a[1], and a[2].
//If the company has any employees at all, a[sp-1] is always is the name of the
//most recently hired one.

int main()
{
	int n {100}; //maximum number of people you can employ simultaneously
	string a[n]; //Store the stack in an array of n strings.
	int sp {0};  //the "stack pointer": subscript of 1st unoccupied element

	cout    << "Type a name (one word) to hire a person.\n"
		<< "Type fire to fire the most recently hired person.\n"
		<< "Type exit to exit the program.\n";

	for (;;) {   //Infinite loop, until we break out below.
		cout << "\nGo ahead: ";
		string word;
		cin >> word;

		if (word == "exit") {
			cout << "Goodbye.\n";
			break;   //out of the for loop.
		} else if (word == "fire") {
			if (sp == 0) {
				cerr << "Sorry, the stack is already empty.\n";
			} else {
				--sp;
				cout << "Firing " << a[sp] << ".\n";
			}
		} else {   //If none of the above, assume the word is a name.
			if (sp == n) {
				cerr << "Sorry, the stack already contains "
					<< sp << " people.\n";
			} else {
				a[sp] = word;
				cout << "Hiring " << a[sp] << ".\n";
				++sp;
			}
		}
	}

	return EXIT_SUCCESS;   //Arrive here when the user types exit.
}