Sunday, 18 November 2018

Time Class and Its Implementation in C++

Leave a Comment

Time.h

#ifndef TIME_H
#define TIME_H

class Time
{
    public:
        Time();
        Time(int,int,int);
        virtual ~Time();
        Time(const Time& other);
        int Gethour() { return hour; }
        void Sethour(int val) { hour = val; }
        int Getminutes() { return minutes; }
        void Setminutes(int val) { minutes = val; }
        int Getseconds() { return seconds; }
        void Setseconds(int val) { seconds = val; }
    protected:
    private:
        int hour;
        int minutes;
        int seconds;
};
#endif // TIME_H

Time.cpp

#include "Time.h"
Time::Time()
{
    this.Sethour(0);
    this.Setminutes(0);
    this.Setseconds(0);
}
Time::Time(int hour,int minut,int sec)
{
    this.Sethour(hour);
    this.Setminutes(minut);
    this.Setseconds(sec);
}
Time::~Time()
{
    //dtor
}
Time::Time(const Time& other)
{
    //copy ctor
}


main.cpp

#include <iostream>
#include "Time.h"
using namespace std;
int main()
{
    Time myTime=new Time();
   
    cout << "Hello world!" << endl;
    return 0;
}
If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: