Answer to Question #193016 in C++ for Ajith M

Question #193016

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


1
Expert's answer
2021-05-13T09:56:24-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment