/* ** $Id: weirdcounter,v 1.2 2003/01/27 16:30:48 phf Exp $ ** ** Copyright (c) 2003 by Peter H. Froehlich . ** Freely distributable for educational purposes. */ #ifndef _CS14_WEIRDCOUNTER #define _CS14_WEIRDCOUNTER #include #include "counter" namespace cs14 { class WeirdCounter: public Counter { float x, y, z; public: WeirdCounter( int k, int t ) throw (std::domain_error): x(k*2.5),y(t*1.6),z(0.0*(k+t)) { if ( !((k < 0) and (0 < t)) ) { throw std::domain_error( "new" ); } } int lower() const { return (int) (x / 2.5); } int upper() const { return (int) (y / 1.6); } int get() const { return (int) (z / 1.0); } void set( int m ) throw (std::domain_error) { if ( (((int)(x/2.5)) <= m) and (m <= ((int)(y/1.6))) ) { z = m / 1.0; } else { throw std::domain_error( "set" ); } } void inc() throw (std::domain_error) { if (z < (y/1.6)) { z += 1.0; x += 0.1; } else { throw std::domain_error( "inc" ); } } void dec() throw (std::domain_error) { if ((x/2.5) < z) { z -= 1.0; y -= 0.1; } else { throw std::domain_error( "dec" ); } } }; // WeirdCounter } // namespace cs14 #endif /* _CS14_WEIRDCOUNTER */