All pastes #56379 Raw Edit

Stuff

public text v1 · immutable
#56379 ·published 2006-05-16 21:55 UTC
rendered paste body
#ifndef TTIME_H
#define TTIME_H

using namespace std;

//The Time Class
///////////////////////////////////////
class Time
{
public:
	Time():hh(0),mm(0),ss(0){}
	Time(int h, int m, int s):hh(h),mm(m),ss(s){}
	Time(unsigned long int s){*this = stot(s);}
	~Time(){}

	void display() const;
	void incroment(){*this = stot(ttos() + 1);}

	int gethh() const {return hh;}
	int getmm() const {return mm;}
	int getss() const {return ss;}

	void sethh(int h){hh = h;}
	void setmm(int m){mm = m;}
	void setss(int s){ss = s;}
	void set_time(unsigned long int s){*this = stot(s);}
	void set_time(int h, int m, int s){ hh=h;mm=m;ss=s;}

	Time operator + (const Time &);
	Time operator - (const Time &);
	Time operator +=(const Time &);
	Time operator -=(const Time &);

	//Voithitikes sunartiseis metatropis
	unsigned long int ttos(void) const; //Time To Seconds
private:
	Time stot(unsigned long int) const; //Seconds To Time
	//Eswterika Dedomena
	int hh,mm,ss;
};


///////////////////////////////////////
void Time::display() const
{
	if (hh < 10) cout << "0";
	cout << hh << ":";
	if (mm < 10) cout << "0";
	cout << mm << ":";
	if (ss < 10) cout << "0";
	cout << ss << endl;
}
/*************************************/
Time Time::operator + (const Time &rt)
{
	return stot(this->ttos() + rt.ttos());
}
/*************************************/
Time Time::operator - (const Time &rt)
{	
	return stot( (3600*24 + this->ttos() )
		 	      - rt.ttos());
}
/*************************************/
Time Time::operator += (const Time &t)
{
	*this = stot(this->ttos() + t.ttos());
	return *this;
}
/*************************************/
Time Time::operator -= (const Time &t)
{
	*this = stot( (3600*24 + this->ttos() )
			       - t.ttos());
	return *this;
}
/*************************************/
/* Voithitikes Sinartiseis Metatropes*/
/*************************************/
Time Time::stot(unsigned long int s) const
{
	Time temp;	
	temp.setss(s % 60);
	s  = s / 60;
	temp.setmm(s % 60);
	temp.sethh((s / 60) % 24);// 0<=hh<24

	return temp;
}
unsigned long int Time::ttos(void) const
{
	unsigned long int temp;
	temp = ( this->gethh()*3600 +
		 this->getmm()*60   +
		 this->getss() );

	return temp;
}
///////////////////////////////////////
#endif