C++ Question
Need help with this assignment?Get an original answer from a qualified tutor — from $10/page.
Get it written →
In c++, Define a class counterType to implement a counter. Your class must have a private data member counterof type int. Define a constructor that accepts a parameter of type int and initializes the counterdata member. Add functions to:
- Set
counterto the integer value specified by the user. - Initialize
counterto 0. - Return the value of counter with a function named
getCounter. - Increment and decrement counter by one.
- Print the value of counter using the
printfunction.- Example output:
Counter = 0.
- Example output:
The value of counter must be nonnegative.
Task 1: Included the private member variable counter
Task 2: counterType‘s getCounterreturns the value of counter
Task 3: counterType‘s incrementCounter increments the value of counter
Task 4: counterType‘s decrementCounter decrements the value of counter
Task 5: counterType‘s print prints the value of counter
The file name counterTypelmp.cpp has been named..
main.cpp was provided:
#include <iostream>
#include “counterType.h”
#include<string>
using namespace std;
int main()
{
counterType counter1;
counterType counter2(5);
counter1.print();
cout << endl;
counter1.incrementCounter();
cout << “After Increment counter1: ” << counter1.getCounter() << endl;
cout << “Counter2 = ” << counter2.getCounter() << endl;
counter2.decrementCounter();
cout << “After decrement counter2 = ” << counter2.getCounter() << endl;
counter1.setCounter(-6);
cout << “After resetting counter1: ” << counter1.getCounter() << endl;
return 0;
}
Get a plagiarism-free answer to this question
Send us your instructions and we’ll match you with the best writer in your subject.
- 100% human-written, zero AI
- Turnitin report included
- Confidential — we never share your data
- Free revisions & refunds