#ifndef COFFEE_H #define COFFEE_H #include //forward declaration of ostream (lighter than ) class coffee { int mg; //caffeine remaining, in milligrams (>= 0) public: coffee(int init_mg); coffee(); //default constructor coffee& operator+=(int n); //add caffeine coffee& operator-=(int n); //subtract caffeine coffee& operator++(); //prefix ++ (add 1 mg) const coffee operator++(int);//postfix ++ (return old value, then add 1) coffee& operator--(); //prefix -- const coffee operator--(int);//postfix -- friend std::ostream& operator<<(std::ostream& os, const coffee& c); //Friends that use two objects of the same class often become friends. friend int operator-(const coffee& a, const coffee& b); //difference in mg friend bool operator==(const coffee& a, const coffee& b); friend bool operator<(const coffee& a, const coffee& b); //Define the rest in terms of == and < (no need to touch private data). }; inline bool operator!=(const coffee& a, const coffee& b) { return !(a == b); } inline bool operator>(const coffee& a, const coffee& b) { return (b < a); } inline bool operator<=(const coffee& a, const coffee& b) { return !(b < a); } inline bool operator>=(const coffee& a, const coffee& b) { return !(a < b); } //Two flavors of operator+ (implemented using operator+=) inline const coffee operator+(coffee c, int n) { c += n; return c; } //coffee + int inline const coffee operator+(int n, coffee c) { c += n; return c; } //int + coffee inline const coffee operator-(coffee c, int n) { c -= n; return c; } //coffee - int #endif