Help writing a Class CounterType program

Honestly guys, I have no idea how to even start this program. Or really write it, since I don't even know where to start. If someone could please help me with this, I would greatly appreciate it. This is for a beginning CompSci course at my school. Here is the program description:



Define 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 non-negative whole number.

Include a mutator function that sets the counter to a count given as an
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. Embed your class definition in a test program
and run sufficient tests to verify it all works correctly.

 
  //I don't know how to start!!! 
Last edited on
First step is to make a class called CounterType and put in all private attribute and public members.

From what I can tell, all the class does is count. This means you would only have one attribute called counter.

For member functions it looks like you need a function that sets the value of counter by passing in an integer. Make sure you check that the integer passed in was positive.

You also need an increment function and a decrement function. These are very simple but the decrement needs to check that it will not be dropping below zero.

The last functions just return whatever counter is.

If I am understanding the prompt correctly, the point of the assignment is to get more comfortable with classes as well as learning about how to react to illegal calls. If you don't know how to throw exceptions, then I assume you just do nothing if an illegal call is made.

Good Luck!
Last edited on
Please don't post the same question multiple times.
http://www.cplusplus.com/forum/general/130698/
^
closed account (j3Rz8vqX)
No idea? So what do you want help with, interpretations?

Make a class called CounterType.

It will have a private member called count? of integer type.

Have a public member function(method) to allow you to modify count; with it's passed argument. Also enforce rules - count positive and a whole number: unsigned int?

Have a public member function(method) to increment and decrement count by one? Enforce rules.

Double check that every method enforces positive value of count rule.

Have a public member function(method) to return the value of count.

Have a public member function(method) to prints the value of count; cout.

Make a main function and integrate your class. Test it. Test it a "sufficient" amount of time. Verify it works.

Doesn't sound too difficult.

Trial and error on syntax.
http://www.cplusplus.com/doc/tutorial/classes/
I'll be honest, I don't know comp sci. I just need this to be done to get through the class. Be a bro?
Topic archived. No new replies allowed.