64,676
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cmath>
using namespace std;
class MyTime{
private:
int hours;
int mins;
public:
MyTime();
MyTime(int h,int m);
void addMins(int m);
void addHours(int h);
void display();
MyTime operator-(const MyTime& mt)const ;
MyTime operator+(const MyTime& mt)const ;
bool operator>=(const MyTime& mt) const;
bool operator<=(const MyTime& mt) const;
bool operator<(const MyTime& mt) const;
bool operator!=(const MyTime& mt) const;
};
void MyTime::addMins(int m){
mins+=m;
}
void MyTime::addHours(int h){
hours+=h;
}
void MyTime::display(){
if(mins>=0){
hours+=mins/60;
mins%=60;
}
else{
hours--;
hours-=abs(mins)/60;
mins=abs(mins)%60;
}
cout<<hours<<endl;
cout<<mins<<endl;
}
MyTime MyTime::operator+(const MyTime& mt) const{
MyTime T;
T.mins=mins+mt.mins;
T.hours=hours+mt.hours;
return T;
}
MyTime MyTime::operator-(const MyTime & mt) const{
MyTime T;
T.mins=mins-mt.mins;
T.hours=mins-mt.mins;
return T;
}
bool MyTime::operator>=(const MyTime & mt) const{
return (hours*60+mins)>=(mt.hours*60+mt.mins);
}
bool MyTime::operator<(const MyTime & mt) const{
return (hours*60+mins)<(mt.hours*60+mt.mins);
}
bool MyTime::operator<=(const MyTime & mt) const{
return (hours*60+mins)<=(mt.hours*60+mt.mins);
}
bool MyTime::operator!=(const MyTime & mt) const{
return (hours*60+mins)!=(mt.hours*60+mt.mins);
}
#include <iostream>
#include <cmath>
using namespace std;
class MyTime{
private:
int hours;
int mins;
public:
MyTime();
MyTime(int h,int m);
void addMins(int m);
void addHours(int h);
void display();
MyTime operator-(const MyTime & mt)const ;
MyTime operator+(const MyTime& mt)const ;
bool operator>=(const MyTime& mt) const;
bool operator<=(const MyTime& mt) const;
bool operator<(const MyTime& mt) const;
bool operator!=(const MyTime& mt) const;
};
int main()//为了完整加的
{
MyTime mytime(5,3);
mytime.display();
return 0;
}
MyTime::MyTime()//这个函数原来没定义,加上就好了
{
hours=mins=0;
}
MyTime::MyTime(int h,int m)//这个也是
{
hours=h;
mins=m;
}
void MyTime::addMins(int m){
mins+=m;
}
void MyTime::addHours(int h){
hours+=h;
}
void MyTime::display(){
if(mins>=0){
hours+=mins/60;
mins%=60;
}
else{
hours--;
hours-=abs(mins)/60;
mins=abs(mins)%60;
}
cout<<hours<<endl;
cout<<mins<<endl;
}
MyTime MyTime::operator+(const MyTime& mt) const{
MyTime T;
T.mins=mins+mt.mins;
T.hours=hours+mt.hours;
return T;
}
MyTime MyTime::operator-(const MyTime & mt) const{
MyTime T;
T.mins=mins-mt.mins;
T.hours=mins-mt.mins;
return T;
}
bool MyTime::operator>=(const MyTime & mt) const{
return (hours*60+mins)>=(mt.hours*60+mt.mins);
}
bool MyTime::operator<(const MyTime & mt) const{
return (hours*60+mins)<(mt.hours*60+mt.mins);
}
bool MyTime::operator<=(const MyTime & mt) const{
return (hours*60+mins)<=(mt.hours*60+mt.mins);
}
bool MyTime::operator!=(const MyTime & mt) const{
return (hours*60+mins)!=(mt.hours*60+mt.mins);
}
#include <iostream>
#include <cmath>
using namespace std;
class MyTime{
private:
int hours;
int mins;
public:
MyTime(){}//
MyTime(int h,int m): hours(h), mins(m){}//这两个函数没定义
void addMins(int m);
void addHours(int h);
void display();
MyTime operator-(const MyTime& mt)const ;
MyTime operator+(const MyTime& mt)const ;
bool operator>=(const MyTime& mt) const;
bool operator<=(const MyTime& mt) const;
bool operator<(const MyTime& mt) const;
bool operator!=(const MyTime& mt) const;
};
void MyTime::addMins(int m){
mins+=m;
}
void MyTime::addHours(int h){
hours+=h;
}
void MyTime::display(){
if(mins>=0){
hours+=mins/60;
mins%=60;
}
else{
hours--;
hours-=abs(mins)/60;
mins=abs(mins)%60;
}
cout<<hours<<endl;
cout<<mins<<endl;
}
MyTime MyTime::operator+(const MyTime& mt) const{
MyTime T;
T.mins=mins+mt.mins;
T.hours=hours+mt.hours;
return T;
}
MyTime MyTime::operator-(const MyTime & mt) const{
MyTime T;
T.mins=mins-mt.mins;
T.hours=mins-mt.mins;
return T;
}
bool MyTime::operator>=(const MyTime & mt) const{
return (hours*60+mins)>=(mt.hours*60+mt.mins);
}
bool MyTime::operator<(const MyTime & mt) const{
return (hours*60+mins)<(mt.hours*60+mt.mins);
}
bool MyTime::operator<=(const MyTime & mt) const{
return (hours*60+mins)<=(mt.hours*60+mt.mins);
}
bool MyTime::operator!=(const MyTime & mt) const{
return (hours*60+mins)!=(mt.hours*60+mt.mins);
}