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

Write the interface (.h file) of a class Counter containing: An instance variabl

ID: 3537350 • Letter: W

Question

Write the interface (.h file) of a class Counter containing:
An instance variable counter of type int , initialized to 0. A function called increment that adds one to the instance variable counter . It does not accept parameters or return a value. A function called getValue that doesn't accept any parameters. It returns the value of the instance variable counter . A default constructor. Write the interface (.h file) of a class Counter containing:
An instance variable counter of type int , initialized to 0. A function called increment that adds one to the instance variable counter . It does not accept parameters or return a value. A function called getValue that doesn't accept any parameters. It returns the value of the instance variable counter . A default constructor.

Explanation / Answer

This is a good and tricky one because in .h files, no variables can be initialized

So the counter value will not be initialized here.



and as it is an interface. there ll be no body definition, only declaration. if you define anything inside body, thats incorrect.




class Counter {

private:

int counter;


public:

void increment();

int getValue();

Counter();

};





hope it helps you