#include <iostream>
using namespace std;
class Age
{
private:
int hours;
public:
Age(int hours): hours(hours) {}
Age(int days, int hours): hours(hours)
{
Age numDays(days);
while(numDays.hours)
{
numDays--;
this->hours += 24;
}
}
Age operator--(int)
{
return Age(hours--);
}
bool operator==(const Age& other) const
{
return hours == other.hours;
}
bool operator<(const Age& other) const
{
return hours < other.hours;
}
bool operator>(const Age& other) const
{
return hours > other.hours;
}
};
int main()
{
Age A1(9);
if (A1 < 24)
cout << "\nMoon cannot Sighted";
else
cout << "\n Moon Sighted";
//Object via 2-Arg Constructor, first arg is day and second arg is hours
Age A3(1, 9); //Overloaded Decrement operator is called in this constructor
//which converts days and hours in hours
if (A3 < 24)
cout << "\nMoon cannot Sighted";
else
cout << "\n Moon Sighted";
return 0;
}
Comments
Leave a comment