Answer:
class Counter {
public:
int counter;
Counter(int counter) { // Constructor
counter = counter;
}
void increment(){
counter++;
}
void decrement(){
counter--;
}
int getValue(){
return counter;
}
};
<h2><u>
Explanation:</u></h2>
// Class header definition for Counter class
class Counter {
// Write access modifiers for the properties(data members) and methods
public:
//a. Create data member counter of type int
int counter;
//b. Create a constructor that takes one int argument and assigns
// its value to counter.
Counter(int counter) { // Constructor with argument counter
counter = counter; // Assign the argument counter to the data
// member counter
}
// c. Create a function increment that accepts no parameters
// and returns no value (i.e void)
void increment(){
counter++; // d. increment adds one to the counter data member
}
// e. Create a function decrement that accepts no parameters
// and returns no value (i.e void)
void decrement(){
counter--; // f. decrement subtracts one from the counter data member
}
// g. Create a function called getValue that accepts no parameters.
// The return type is int, since the data member to be returned is of
// type int.
int getValue(){
return counter; // h. it returns the value of the instance var counter
}
}; // End of class declaration
Hope this helps!