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

write a class called counter that represents a simple tally counter, which might

ID: 3854236 • Letter: W

Question

write a class called counter that represents a simple tally counter, which might be used to count people as they enter a room. the counter class should contain a single integer as instance data, representing the count. write aconstructor to initialized the count to zero. write a method called click that increments the count and another method called getcount that returns the cur-rent count. include a method called reset that resets the counter to zero.finally, create a driver class called countertest that creates two counter objects and test their methods

Explanation / Answer

code:

#include <iostream>
#include<map>
#include<stack>
#include<vector>
#include<algorithm>
#include <fstream>
#include<cstdlib>
using namespace std;

class Counter
{
public:
int count;
Counter()
{
count=0;
}
void click()
{
count++;
}
int getcount()
{
return count;
}
void reset()
{
count=0;
}
};
class Countertest
{
public:
Counter c1;
Counter c2;
Countertest()
{

}
void test()
{
c1.click();
c2.click();
cout<<"c1 count: "<< c1.getcount()<<endl;
cout<<"c2 count: "<<c2.getcount();
}
};


int main()
{
Countertest ct1;
ct1.test();
return 0;
}