Question: Define a class for a type called Counter. An object of this type is used to count things. Include a default constructor that sets the

Define a class for a type called Counter. An object of this type is used to count things. 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. Write member functions to increase the value by one (called increment) and decrease the value by one (called decrement), don't let the value go below zero. Write a member function (print) that prints out the value of the counter.
Here's a driver program that you should include to test your class.
\table[[39,,main()],[40,,2],[41,,Counter c1;],[42,,Counter c2(10);],[43,,],[44,,cout "C1 starts at ";],[45,,c1.print();],[46,,cout endl;],[47,,],[48,,c1.increment();],[49,,c1.increment();],[50,,],[51,,cout "C1 now at ";],[52,,c1.print();],[53,,cout endl;],[54,,],[55,,c1=c2;
Define a class for a type called Counter. An

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!