Answer on Question# 47608- <engineering> - <other>
Program:
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class Counter
{
private:
int currentVal;
public:
Counter(int val=0) {currentVal=val;}
void Increment(){currentVal++;}
void Decrement(){currentVal--;}
void printValue(){cout<<"Value="<<currentval<<endl;}
};
int main()
{
Counter myCounter(5);
cout<<"After constructor (5): ";
myCounter.printValue();
myCounter.Increment();
cout<<"After increment: "; myCounter.printValue();
myCounter.Decrement();
cout<<"After decrement: "; myCounter.printValue();
getch();
return 1;
}Result of executing of program:
After constructor <5>: Value=5
After increment: Value=6
After decrement: Value=5https://www.assignmentexpert.com/</currentval<<endl></string></conio.h></iostream>
Comments