text: // sales.h  -- exceptions and inheritance
  #include <stdexcept>
  #include <string>
  
  class Sales
  {
  	public:
  		enum {MONTHS = 12};   // could be a static const
      
  		class bad_index : public std::logic_error
  		{
  			private:
  				int bi;  // bad index value
  
  			public:
  				//constructor
  				explicit bad_index(int ix, const std::string & s = "Index error in Sales object\n");
  				virtual ~bad_index() throw() {}
  
  				//other method
  				int bi_val() const {return bi;}
  			
  
  		};
      
  		//constructor
  		explicit Sales(int yy = 0);
  		Sales(int yy, const double * gr, int n);
  		virtual ~Sales() { }
      
  		//other method
  		int Year() const { return year; }
  		virtual double operator[](int i) const;
  		virtual double & operator[](int i);
  
  	private:
  		double gross[MONTHS];
  		int year;
  
  };
  
  class LabeledSales : public Sales
  {
  	public:
  		class nbad_index : public Sales::bad_index
  		{
  			private:
  				std::string lbl;
  			public:
  				//
  				nbad_index(const std::string & lb, int ix, const std::string & s = "Index error in LabeledSales object\n");
  				const std::string & label_val() const {return lbl;}
  				virtual ~nbad_index() throw() {}
  		};
  		
  		//constructor
  		explicit LabeledSales(const std::string & lb = "none", int yy = 0);
  		LabeledSales(const std::string & lb, int yy, const double * gr, int n);
  		virtual ~LabeledSales() { }
  		
  		//other methods
  		const std::string & Label() const {return label;}
  		virtual double operator[](int i) const;
  		virtual double & operator[](int i);
  
  	private:
  		std::string label;
  };
  