#include <iostream.h>
#include <stdlib.h>

class Exception
{
public:
	virtual unsigned severity () = 0;
};

class Typo : public Exception
{
public:
	Typo (char inTyped);
	unsigned severity ();
	char getTyped ();
	
private:
	char typed;
};

void getStatus () throw (Exception*);

Typo::Typo (char inTyped)
:typed(inTyped)
{}

unsigned Typo::severity ()
{
	return 1;
}

char Typo::getTyped ()
{
	return typed;
}


class NuclearMeltdown : public Exception
{
public:
	unsigned severity ();
};

unsigned NuclearMeltdown::severity ()
{
	return 10;
}

void getStatus ()
{
	char in;
	
	cout << "Please type a captital O if everything is okay: ";
	cout.flush ();

	cin.get(in);

	if (in == 'o')
		throw new Typo('o');

	if (in != 'O')
		throw new NuclearMeltdown ();
}

void main ()
{
	try
	{
		getStatus ();
	}
	catch (Exception* e)
	{
		if (e->severity() == 1)
		{
			cerr << "Typo detected.\n";
			cerr << "You typed " << ((Typo*) (e))->getTyped() << endl;
			delete e;
		}
		else
		{
			cerr << "Nuclear meltdown!\n";
			delete e;
			exit(1);
		}
	}

	cout << "It's okay!" << endl;
}
