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 greater index using > operator overloading.
#include <iostream>
using namespace std;
class Index
{
private:
int indexValue;
public:
// GetIndex() function
void GetIndex()
{
cin >> indexValue;
}
// operator overloaded function
void operator > (Index i)
{
if(indexValue > i.indexValue)
{
cout << indexValue;
}
else
{
cout << i.indexValue;
}
}
};
int main()
{
Index i1,i2;
// Getting index values from user
cout << "Runtime Input :\n";
i1.GetIndex();
i2.GetIndex();
// Displaying greater index using operator overloaded function
cout << "Output :\n";
i1>i2;
return 0;
}
Comments
Leave a comment