#include<iostream.h>
#include<conio.h>
class Time
{
int hour;
int minute;
int second;
public:
friend int operator==(Time &,Time &);
friend void operator>>(istream &,Time &);
friend void operator<<(ostream &,Time &);
};

int operator==(Time &T1,Time &T2)
{
if(T1.hour==T2.hour&&T1.minute==T2.minute&&T1.second==T2.second)
return(1);
else
return(0);
}

void operator>>(istream & din,Time &T1)
{
cout<<"\nEnter Hours : ";
din>>T1.hour;
cout<<"\nEnter Minutes : ";
din>>T1.minute;
cout<<"\nEnter Seconds : ";
din>>T1.second;
}

void operator<<(ostream &dout,Time &T1)
{
dout<<T1.hour<<" : "<<T1.minute<<" : "<<T1.second;
}

int main()
{
clrscr();
Time T1,T2;
cout<<"\nEnter first time \n";
cin>>T1;
cout<<"\nEnter second time \n";
cin>>T2;

if(T1==T2)
{
cout<<"\n\nTwo times are same";
}
else
{
cout<<"\n\nTwo times are not same";
}
cout<<"\n\nT1 = ";
cout<<T1;
cout<<"\n\nT2 = ";
cout<<T2;
getch();
return 0;
}

Post a Comment

Previous Post Next Post