Bài tập CTime

//
//  CTime.hpp
//  CTime
//
//  Created by Toan Nguyen on 10/20/20.
//

#ifndef CTime_hpp
#define CTime_hpp
#include "CTimeSpan.hpp"
class CTime{
private:
    int h;
    int m;
    int s;
public:
    CTime();
    CTime(int,int,int);
    void ThemGiay(int);
    void TruGiay(int);
    CTimeSpan Tru(const CTime&)const;
    void Them1Giay();
    void Bot1Giay();
    void Nhap();
    void Xuat()const;
};

#endif /* CTime_hpp */

//
//  CTime.cpp
//  CTime
//
//  Created by Toan Nguyen on 10/20/20.
//

#include "CTime.hpp"
#include <math.h>
#include <iostream>
using namespace std;
CTime::CTime():h(0),m(0),s(0){
}
CTime::CTime(int hh, int mm, int ss):h(hh),m(mm),s(ss){
    
}
void CTime::Them1Giay(){
    this->ThemGiay(1);
}
void CTime::Bot1Giay(){
    this->TruGiay(1);
}

void CTime::ThemGiay(int ss) {
   //sinh vien tu kiem tra lai
    this->s +=ss;
    int d = this->s/60;
    this->s= this->s %60;
    this->m +=d;
    d = this->m/60;
    this->m = this->m%60;
    this->h +=d;
    this->h=this->h%24;
    //1:1:59 + 100;
    //1:59:1 + 100;
    //23:59:59 + 100;
}

void CTime::TruGiay(int) { 
    //tuong tu them giay
}

CTimeSpan CTime::Tru(const CTime &t2) const {
    long d1 = this->h*3600+this->m*60+this->s;
    long d2 = t2.h*3600+t2.m*60+t2.s;
    return CTimeSpan(abs(d1-d2));
}

void CTime::Nhap() { 
    cout << "Nhap gio:";
    cin >> this->h;
    cout << "Nhap phut:";
    cin >> this->m;
    cout << "Nhap giay:";
    cin >> this->s;
    cin.ignore();
}

void CTime::Xuat() const { 
    cout << this->h << ":"<<this->m<<":"<<this->s<<endl;
}