26b)Create
a C++ class Time with data members hours, minutes, seconds. Write a C++ program
using
11.>>
To accept the time.
111<<
To display the time.
#include<stdio.h>
#include<string.h>
#include<iostream.h>
{
int
hours;
int
minutes;
int
second;
public:
friend
istream & operator >>(istream &, time &);
friend
ostream & operator <<(ostream &, time &);
int
operator !=(time t2);
};
istream
& operator >>(istream & stream, time & t)
{
return
stream >>t.hours>>t.minutes>>t.second;
}
ostream
& operator <<(ostream & stream, time & t)
{
return
stream <<t.hours<<":"<<t.minutes<<":"<<t.second;
}
int
time::operator !=(time t2)
{
if(hours==t2.hours&&minutes==t2.minutes&&second==t2.second)
return
1;
return
0;
}
{
time
t1,t2;
clrscr();
cout<<"\n
Enter time as hour,minutes,seconds :";
cin>>t1;
cout<<"\n
Enter time as hour,minutes,seconds :";
cin>>t2;
cout<<"\n
First Time is :";
cout<<t1;
cout<<"\n
Second Time is :";
cout<<t2;
if(t1!=t2)
cout<<"\nBoth
times are equal";
else
cout<<"\n
Time not equal";
getch();
return
0;
}