![]() |
#2
zxwangyun2012-06-12 15:39
|

#include<iostream>
using namespace std;
class time
{
private:
int h,m,s;
public:
time (int a,int b,int c);
void operator +(time t1);
void operator -(time t1);
void shuchu();
};
time::time(int a,int b,int c)
{
h=a;
m=b;
s=c;
cout<<h<<":"<<m<<":"<<s<<endl;
}
void time::operator +(time t1)
{
s=s+t1.s;
if(s>=60)
{
s-=60;
m++;
}
m=m+t1.m;
if(m>=60)
{
m-=60;
h++;
}
h=h+t1.h;
}
void time::operator -(time t1)
{
s=s+t1.s;
if(s<0)
{
s+=60;
m--;
}
m=m+t1.m;
if(m<0)
{
m+=60;
h--;
}
h=h+t1.h;
}
void time::shuchu()
{
cout<<h<<":"<<m<<":"<<s<<endl;
}
int main()
{
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
time t1(a,b,c),t2(d,e,f),t3(0,0,0);
t3=t1+t2; //no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) 这是什么意思啊?
t3.shuchu();
return 0;
}
using namespace std;
class time
{
private:
int h,m,s;
public:
time (int a,int b,int c);
void operator +(time t1);
void operator -(time t1);
void shuchu();
};
time::time(int a,int b,int c)
{
h=a;
m=b;
s=c;
cout<<h<<":"<<m<<":"<<s<<endl;
}
void time::operator +(time t1)
{
s=s+t1.s;
if(s>=60)
{
s-=60;
m++;
}
m=m+t1.m;
if(m>=60)
{
m-=60;
h++;
}
h=h+t1.h;
}
void time::operator -(time t1)
{
s=s+t1.s;
if(s<0)
{
s+=60;
m--;
}
m=m+t1.m;
if(m<0)
{
m+=60;
h--;
}
h=h+t1.h;
}
void time::shuchu()
{
cout<<h<<":"<<m<<":"<<s<<endl;
}
int main()
{
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
time t1(a,b,c),t2(d,e,f),t3(0,0,0);
t3=t1+t2; //no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) 这是什么意思啊?
t3.shuchu();
return 0;
}