Create a class Index which keeps track of the Index value. Include member function GetIndex() to read index value.Write an overloaded function to display the index value after post- increment and pre-decrements the Index value
#include <iostream>
using namespace std;
class Index{
int i;
public:
Index(): i(0){}
void GetIndex(){
cout<<"Input index: ";
cin>>i;
}
void operator++(int){ //post increment
cout<<++i<<endl;
}
void operator--(){ //pre-decrement
cout<<--i<<endl;
}
};
int main(){
Index index;
index.GetIndex();
index++;
--index;
return 0;
}
Comments
Leave a comment