Time Difference
Time Difference
Just open your c++ compiler Paste this code.
#include<iostream>
using namespace std;
class time
{
private :
int hour,minutes,seconds;
public :
time() : hour(0),minutes(0),seconds(0)
{
}
time(int hr,int min,int sec) : hour(hr), minutes(min), seconds(sec)
{
}
void display()
{
cout<<hour<<":";
cout<<minutes;
cout<<":";
cout<<seconds;
cout<<"\n";
}
void add(int x,int y,int z,int n,int m,int o)
{
int p;
int q;
int r;
p=x+n;
q=y+m;
r=z+o;
cout<<"the time after add is ";
cout<<p<<":"<<q<<":"<<r;
}
};
int main()
{
int a,b,c,d,e,f;
time time3;
cout<<"enter the hours =";
cin>>a;
cout<<"enter the minutes =";
cin>>b;
cout<<"enter the seconds =";
cin>>c;
cout<<"enter the hours =";
cin>>d;
cout<<"enter the minutes =";
cin>>e;
cout<<"enter the seconds =";
cin>>f;
for(int h=0;h<=2;h--)
{
if (b>=60)
{
b-=60;
a++;
}
else if (c>=60)
{
c-=60;
b++;
}
else if (e>=60)
{
e-=60;
d++;
}
else if (f>=60)
{
f-=60;
e++;
}
else if (b<60 && c<60 && e<60 && f<60)
{
break;
}
}
time time1(a,b,c);
time time2(d,e,f);
if(a>24)
{
cout<<"the time 1 exceeds the 24 hours format\n";
cout<<"but the time given is";
time1.display();
cout<<"\n";
}
if(d>24)
{
cout<<"the time 2 exceeds the 24 hours format\n";
cout<<"but the time given is";
time2.display();
cout<<"\n";
}
if(a<24)
{
cout<<"the time 1 is";
time1.display();
}
if(d<24)
{
cout<<"the time 2 is";
time2.display();
}
time3.add(a,b,c,d,e,f);
}
Just open your c++ compiler Paste this code.
#include<iostream>
using namespace std;
class time
{
private :
int hour,minutes,seconds;
public :
time() : hour(0),minutes(0),seconds(0)
{
}
time(int hr,int min,int sec) : hour(hr), minutes(min), seconds(sec)
{
}
void display()
{
cout<<hour<<":";
cout<<minutes;
cout<<":";
cout<<seconds;
cout<<"\n";
}
void add(int x,int y,int z,int n,int m,int o)
{
int p;
int q;
int r;
p=x+n;
q=y+m;
r=z+o;
cout<<"the time after add is ";
cout<<p<<":"<<q<<":"<<r;
}
};
int main()
{
int a,b,c,d,e,f;
time time3;
cout<<"enter the hours =";
cin>>a;
cout<<"enter the minutes =";
cin>>b;
cout<<"enter the seconds =";
cin>>c;
cout<<"enter the hours =";
cin>>d;
cout<<"enter the minutes =";
cin>>e;
cout<<"enter the seconds =";
cin>>f;
for(int h=0;h<=2;h--)
{
if (b>=60)
{
b-=60;
a++;
}
else if (c>=60)
{
c-=60;
b++;
}
else if (e>=60)
{
e-=60;
d++;
}
else if (f>=60)
{
f-=60;
e++;
}
else if (b<60 && c<60 && e<60 && f<60)
{
break;
}
}
time time1(a,b,c);
time time2(d,e,f);
if(a>24)
{
cout<<"the time 1 exceeds the 24 hours format\n";
cout<<"but the time given is";
time1.display();
cout<<"\n";
}
if(d>24)
{
cout<<"the time 2 exceeds the 24 hours format\n";
cout<<"but the time given is";
time2.display();
cout<<"\n";
}
if(a<24)
{
cout<<"the time 1 is";
time1.display();
}
if(d<24)
{
cout<<"the time 2 is";
time2.display();
}
time3.add(a,b,c,d,e,f);
}







