// class test 2007/5/25 16:40-18:46:54
//g++ -pipe -o p10 p10.cpp && p10
#include <iostream>
using namespace std;
class CTime {
private:
int hour, min;
float sec;
public:
CTime() {}
CTime(const CTime & ct):hour(ct.hour), min(ct.min), sec(ct.sec) {}
CTime(int h, int m, float s):hour(h), min(m), sec(s) {}
void show_time() {
cout << hour << "hr " << min << "min " << sec << "sec" << endl;
}
CTime& operator=(const CTime & ct);
CTime operator*(const int &multiple) const;
friend CTime operator*(const int &multiple, const CTime & ct);
};
CTime & CTime::operator=(const CTime & ct){
if (&ct != this) {
hour = ct.hour, min = ct.min, sec = ct.sec;
return *this;
}
}
CTime operator*(const int &multiple, const CTime & ct){
return ct * multiple;
}
CTime CTime::operator*(const int &multiple)const{
double timeValue = ((hour * 60) + min) * 60 + sec;
timeValue *= multiple;
int _min = (int)timeValue / 60;
float _sec = timeValue - _min * 60;
int _hour = _min / 60;
_min %= 60;
return CTime(_hour, _min, _sec);
}
int main(void){
CTime t1(6, 14, 21.3);
CTime t2 = t1 * 3;
t2.show_time();
CTime t3 = 2 * t1;
t3.show_time();
CTime ta(6, 14, 21.3);
CTime tb, tc, td;
td = tc = tb = ta;
tb.show_time();
tc.show_time();
td.show_time();
system("PAUSE");
return 0;
}
g++ -pipe -o p10 p10.cpp && p10
18hr 43min 3.9sec
12hr 28min 42.6sec
6hr 14min 21.3sec
6hr 14min 21.3sec
6hr 14min 21.3sec
PAUSE: Permission denied