71.2k views
4 votes
Write the definition of a class counter containing: an instance variable counter of type int, initialized to 0. a method called increment that adds one to the instance variable counter. it does not accept parameters or return a value. a method called getvalue that doesn't accept any parameters. it returns the value of the instance variable counter.

User Agoldencom
by
6.8k points

1 Answer

2 votes
class Counter
{
private:
int counter = 0;
public:
void Increment() { counter++; }
int GetValue() { return counter; }
};


User Nicolo
by
6.3k points