Answer to Question #182312 in C++ for Vijay Raj

Question #182312

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.

Runtime Input :

9

4

Output :

9


1
Expert's answer
2021-04-18T19:44:58-0400
#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;
}







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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS