17. Create a class Time which contains: – hours – minutes – second Write a C++ program using operator overloading for the following: 1. = = to check whether two Times are same or not. 2. >> to accept the time. 3. << to display the time .


#include<iostream.h>
#include<conio.h>
class time
{
public:
int hour;
int minute;
int second;
public:
friend istream &operator>>(istream &scan,time &t)
{
scan>>t.hour>>t.minute>>t.second;
return scan;
}
friend ostream &operator<<(ostream &print,time &t)
{
print<<t.hour<<“:”<<t.minute<<“:”<<t.second;
return print;
}
void operator==(time z)
{
if(hour==z.hour&&minute==z.minute&&second==z.second)
{
cout<<“\nBoth the time are same: “;
}
else
{
cout<<“\nTime are not same: “;
}
}
};
void main()
{
time t1,t2;
clrscr();
cout<<“\nEnter the Time 1st: HOUR MINUTE SECOND \n”;
cin>>t1;
cout<<“\nTIME: “;
cout<<t1;
cout<<“\nEnter the Time 2nd: HOUR MINUTE SECOND \n”;
cin>>t2;
cout<<“\nTIME: “;
cout<<t2;
t1==t2;
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s