Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class for a type called CounterType. An instance of the class (or objec

ID: 3657599 • Letter: D

Question

Define a class for a type called CounterType. An instance of the class (or object) is used for counting objects. The class is a Abstract Data Type. a. Define and implement a default constructor which sets the counter to 0. b. Define and implement a constructor with one parameter which sets the value to a certain value. c. Define and implement a member function to increase the counter by one and another member function to decrease the counter by one. d. Define and implement a member function (getfall) e. Define and implement a member function which writes the value of the counter to a stream. This function has one formal parameter of the type ostream. f. Make sure the counter is never less than 0. Use the following program in order to test the class: int main() { CounterType firstCounter; CounterType secondCounter(10); CounterType thirdCounter(-1); cout << "After initialization the values of the three counters are:" << endl; displayCounters(firstCounter, secondCounter, thirdCounter); firstCounter.increment(); secondCounter.decrement(); thirdCounter.increment(); cout << endl << "After increment and decrement the values of the three counters are: " << endl; displayCounters(firstCounter, secondCounter, thirdCounter); for (int i=0; i< 10; i++) { secondCounter.increment(); secondCounter.increment(); secondCounter.decrement(); } cout << endl << "After many increments and decrements the value of the second counter is: " << secondCounter.getCounter() << endl; return 0; }

Explanation / Answer

Define a class for a type 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 bu one and to decrease the value of the counter 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 is what I have so far. The if statement to check if it is positive is where it is getting hung up in the compiler. Also it will not actually use the user input. #include #include using namespace std; class CounterType{ public: void set(int start_count, int number_to_count); void get(int start_count, int number_to_count); void update_positive(); void update_negative(); int get_count(); int get_counts_left(); void output(ostream& outs); private: int start_number;
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote