#ifndef MYTIME
#define MYTIME
//****************************************************************************************
//클래스 선언
//****************************************************************************************
class Time
{
private:
int hours;
int min;
public:
Time();
Time(int h,int m = 0);
void AddMin(int m);
void AddHr(int h);
void Reset(int h = 0, int m =0);
Time operator+(const Time & t) const;
Time operator-(const Time & t) const;
Time operator*(const Time & t) const;
void Show() const;
}
#endif MYTIME

//****************************************************************************************
#include <iostream>
#include "ex2.h"

Time::Time()
{
Hours = minutes = 0;
}
Time ::Time(int h, int m )
{
hours =h;
min = m ;
}
void Time::AddMin(int m)
{
min += m;
hour += min/60;
mim %= 60;
}

void Time::AddHr(int h)
{
hours += h;
}

void Time::Reset(int h, int m)
{
hours = h;
min = m;
}

Time Time::operator +(const Time &t) const
{
Time sum;
sum.min = min +t.min;
sum.hours = hour + t.hours + sum.min / 60;
sum.min %= 60;
return sum;
}

Time Time::operator -(const Time &t) const
{
Time diff;
int tot1, tot2;
tot1 = t.min + 60 * t.hours;
tot2 = min + 60 * hours;

diff.min = (tot2 - tot1) % 60;
diff.hours = (tot2 - tot1) / 60;

return diff;
}

Time Time::operator *(const Time &t) const
{
Time result;
long totalmin = hours * mult * 60 + min * mult;
result.hours = totalmin / 60;
result.min = totalmin % 60;

return result;
}

void Time::Show() const
{
std::cout << hours << "시간," << min <<"분";
}
//****************************************************************************************
// main
#include <iostream>
#include "ex2.h"

void main()
{
using namespace std;

Time weeding(4, 35);
Time waxing(2,47);
Time total;
Time diff;
Time adjusted;

cout << "weeding time = ";
weeding.Show();
cout << endl;

cout << "waxing time =";
waxing.Show();
cout << endl;

cout << "total work time =";
total = weeding + waxing;
total.Show();
cout << endl;

diff = weeding - waxing;
cout << "weeding time - waxing time =";
diff.Show();
cout << endl;

adjusted = total * 1.5;
cout << "adjusted work time = ";
adjusted.Show();
cout << endl;
}


+ Recent posts