/*
write a c++ program to create a class time which contain
-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>
int i;
class time
{
int h,m,s;
public:void accept();
void operator ==(time t2);
void operator >>(time t2);
void operator <<(time t2);
}t1,t2,t3;
void time::accept()
{
i=i+1;
cout<<"\nenter time "<<i<<"\n\n";
cout<<"\nenter the hour:";
cin>>h;
cout<<"\nenter the minutes:";
cin>>m;
cout<<"\nenter the seconds:";
cin>>s;
}
void time::operator ==(time t2)
{
int i=0;
if(t2.h==h)
i=i+1;
if(t2.m==m)
i=i+1;
if(t2.s==s)
i=i+1;
if(i==3)
cout<<"\nboth times are equal";
else
cout<<"\nboth times are not equal";
}
void time::operator >>(time t2)
{
cout<<"\nenter the hour:";
cin>>t2.h;
t3.h=t2.h;
cout<<"\nenter the minutes:";
cin>>t2.m;
t3.m=t2.m;
cout<<"\nenter the seconds:";
cin>>t2.s;
t3.s=t2.s;
}
void time::operator <<(time t2)
{
t2.h=t3.h;
t2.m=t3.m;
t2.s=t3.s;
cout<<"\nhour:-"<<t2.h;
cout<<"\nminutes:-"<<t2.m;
cout<<"\nseconds:-"<<t2.s;
}
int main()
{
clrscr();
cout<<"\n\t\t==to check whether two times are equal or not\n\n";
t1.accept();
t2.accept();
t1==t2;
cout<<"\n\t\tto accept time\n\n";
t2>>t3;
cout<<"\n\t\tdisplay of accepted time\n\n";
t2<<t3;
getch();
return 0;
}
write a c++ program to create a class time which contain
-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>
int i;
class time
{
int h,m,s;
public:void accept();
void operator ==(time t2);
void operator >>(time t2);
void operator <<(time t2);
}t1,t2,t3;
void time::accept()
{
i=i+1;
cout<<"\nenter time "<<i<<"\n\n";
cout<<"\nenter the hour:";
cin>>h;
cout<<"\nenter the minutes:";
cin>>m;
cout<<"\nenter the seconds:";
cin>>s;
}
void time::operator ==(time t2)
{
int i=0;
if(t2.h==h)
i=i+1;
if(t2.m==m)
i=i+1;
if(t2.s==s)
i=i+1;
if(i==3)
cout<<"\nboth times are equal";
else
cout<<"\nboth times are not equal";
}
void time::operator >>(time t2)
{
cout<<"\nenter the hour:";
cin>>t2.h;
t3.h=t2.h;
cout<<"\nenter the minutes:";
cin>>t2.m;
t3.m=t2.m;
cout<<"\nenter the seconds:";
cin>>t2.s;
t3.s=t2.s;
}
void time::operator <<(time t2)
{
t2.h=t3.h;
t2.m=t3.m;
t2.s=t3.s;
cout<<"\nhour:-"<<t2.h;
cout<<"\nminutes:-"<<t2.m;
cout<<"\nseconds:-"<<t2.s;
}
int main()
{
clrscr();
cout<<"\n\t\t==to check whether two times are equal or not\n\n";
t1.accept();
t2.accept();
t1==t2;
cout<<"\n\t\tto accept time\n\n";
t2>>t3;
cout<<"\n\t\tdisplay of accepted time\n\n";
t2<<t3;
getch();
return 0;
}
No comments:
Post a Comment