Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "CTime.h"
- using namespace std;
- CTime::CTime()
- {
- }
- CTime::CTime(int gio_i, int phut_i, int giay_i)
- {
- this->gio_i_ = gio_i;
- this->phut_i_ = phut_i;
- this->giay_i_ = giay_i;
- }
- CTime::~CTime()
- {
- }
- void CTime::nhap(int gio_i, int phut_i, int giay_i)
- {
- this->gio_i_ = gio_i;
- this->phut_i_ = phut_i;
- this->giay_i_ = giay_i;
- }
- void CTime::xuat()
- {
- cout << gio_i_ << " gio, " << phut_i_ << " phut, " << giay_i_ << " giay." << endl;
- }
- int CTime::covert_to_sec()
- {
- int time_i;
- time_i = this->gio_i_ * 3600 + this->phut_i_ * 60 + this->giay_i_;
- return time_i;
- }
- void CTime::covert_to_time(int sec_i)
- {
- int gio_i_ = 0;
- int phut_i_ = 0;
- int giay_i_ = 0;
- gio_i_ = sec_i / 3600;
- sec_i %= 3600;
- phut_i_ = sec_i / 60;
- giay_i_ = sec_i % 60;
- this->nhap( gio_i_, phut_i_, giay_i_);
- }
- void CTime::cong(int sec_i)
- {
- this->covert_to_time(this->covert_to_sec() + sec_i);
- }
- bool CTime::tru(int sec_i)
- {
- if (this->covert_to_sec() - sec_i >= 0)
- {
- this->covert_to_time(this->covert_to_sec() - sec_i);
- return 1;
- }
- return 0;
- }
- CTimeSpan CTime::tru_to_span(CTime time)
- {
- CTimeSpan span;
- if (this->covert_to_sec() - time.covert_to_sec() >= 0)
- {
- span.covert_to_time_span(this -> covert_to_sec() - time.covert_to_sec());
- }
- return span;
- }
- void CTime::cong1giay()
- {
- this->covert_to_time(this->covert_to_sec()+1);
- }
- void CTime::tru1giay()
- {
- this->covert_to_time(this->covert_to_sec() - 1);
- }
- void nhap(CTime &time)
- {
- int gio_i, phut_i, giay_i;
- do
- {
- cout << "Nhap thoi gian (gio phut giay) : ";
- cin >> gio_i >> phut_i >> giay_i;
- } while (gio_i < 0 || phut_i < 0 || giay_i<0);
- if (giay_i > 60)
- {
- phut_i += giay_i / 60;
- giay_i %= 60;
- }
- if (phut_i > 60)
- {
- gio_i += phut_i / 60;
- phut_i %= 60;
- }
- time.nhap(gio_i, phut_i, giay_i);
- }
- int main()
- {
- CTime a(1, 1, 1);
- CTime b(24, 59, 59);
- CTimeSpan c = b.tru_to_span(a);
- c.xuat();
- system("pause");
- }
Add Comment
Please, Sign In to add comment