#include <iostream>
#include <iomanip>
#include <assert.h>
#include <string>
#include <conio.h>
using namespace std;

class person
{
	public:
	person(string name="") {}

	void drive()
	{
		assert ( fuelLevel >= dailyFuelUsage );
		fuelLevel -= dailyFuelUsage;
	}

	void display()
	{
		cout << "Driver: " << myName << "\tFuel level: " << fuelLevel << "/" << gasTankSize << "\tSpent $" << moneySpent << endl;
	}

	virtual void fillup(double price)=0;

	protected:
	double moneySpent;
	int fuelLevel;
	int gasTankSize;
	int dailyFuelUsage;
	string myName;
};

class procrastinator : public person
{
	public:
	procrastinator(string name="")
	{
		myName=name;
		gasTankSize=30;
		fuelLevel=gasTankSize;
		moneySpent=0;
		dailyFuelUsage = 1;
	}
	
	void fillup(double price)
	{	// the procrastinator only fills up when there isn't enough gas to get to work tomorrow
		if ( fuelLevel < dailyFuelUsage )
		{	
			int fuelToBuy = gasTankSize-fuelLevel;
			double todaysFuelCost=price * fuelToBuy;
			moneySpent += todaysFuelCost;
			fuelLevel += fuelToBuy;
		}
	}

};

class nonprocrastinator : public person
{
	public:
	nonprocrastinator(string name="")
	{
		myName=name;
		gasTankSize=30;
		fuelLevel=gasTankSize;
		moneySpent=0;
		dailyFuelUsage = 1;
	}

	void fillup(double price)
	{	// the non-procrastinator fills up as long as the gas tank isn't full
		if ( fuelLevel < gasTankSize )
		{
			int fuelToBuy = gasTankSize-fuelLevel;
			double todaysFuelCost=price * fuelToBuy;
			moneySpent += todaysFuelCost;
			fuelLevel += fuelToBuy;
		}
	}
};

int main()
{
	cout << fixed << setprecision(2);

	// make a procrastinator named Bob
	procrastinator bob("Bob");
	// make a nonprocrastinator named Alice
	nonprocrastinator alice("Alice");

	double baseGasPrice=1.50;
	double priceIncrease=.01;

	int day=1;
	do 
	{
		system ("cls");	// clear the screen

		// calculate today's gas prices
		double todaysPrice=baseGasPrice + (priceIncrease * day);
		cout << "Day: " << day << "\tToday's Price: " << todaysPrice << endl << endl;

		// have each driver drive and burn gas for today
		bob.drive();
		alice.drive();

		// ask them to fill up (bob will only do so if he needs to)
		bob.fillup(todaysPrice);
		alice.fillup(todaysPrice);

		bob.display();
		alice.display();

		if ( _getch() == 27 ) break; // pause for the user to press a key (ESC escapes!)
		day++;
	} while ( true );

	return 0;
}