C++ Question
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;
}
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
