/* THIS IS THE IMPLEMENTATION FILE Grant Chen Due: 10/02/08 CS213 Student ID 908306235 Compiler: Dev-C++ Exercise 4 problem 2 Problem #2: Prob.#2, Ch6, Page 260 Define and test a class for a type called CounterType. An object of this type is used to count things, so it records a count that is a nonnegative whole number. Include a default constructor that sets the counter to zero and a constructor with one argument that sets the counter to the value specified by its argument. Include member functions to increase the count by one and to decrease the count by one. Be sure that no member function allows the value of the counter to become negative. Also include a member function that returns the current count value and one that outputs the count to a stream. This last function should have one formal parameter of type ostream. Embed your class definition in a test program. Header *.h implementation *.cpp #Include "DayofYear.cpp"? test // main() *.cpp zip and submit */ /* { public: CounterType(); // default constructor initialize to zero CounterType(int countValue); // constructor, 1 argument. int counterPlus(int addValue); // function to add. int counterMinus(int minusValue); // function to subtract int returnCounter(); // function to return the value of this. int streamCounter(); // Output to stream. Needs an ostream parameter. private: int count; // value of the CounterType. }; */ #include #include "countertype.h" using namespace std; CounterType::CounterType( ): count(0) // Default constructor {/* This space left blank. */} CounterType::CounterType(int countValue) // User-defined constructor { count = countValue; } int CounterType::counterPlus(int addValue) // Add an int to the count. { count = count + addValue; } int CounterType::counterMinus(int minusValue) // Subtract an int from the count. { if (count - minusValue < 0) // Make sure it doesn't go below zero. cout << "Count cannot be less than zero!" << endl; else count = count - minusValue; } int CounterType::returnCounter() // Return the count value. { return count; } void outputCount(ostream &outputValue) { }// Not yet implemented.*/