#include <iostream>
using namespace std;
class Time
{
public:
Time() { h = 0, m = 0; }
Time(int hours, int minutes);
void AddMinutes(int minutes);
void Display();
private:
int h;
int m;
};
Time::Time(int hours, int minutes)
{
if (hours < 0) h = 0;
else h = hours % 24;
if (minutes < 0) m = 0;
else m = minutes % 60;
}
void Time::AddMinutes(int minutes)
{
if (m + minutes < 60) m += minutes;
else
{
m = (m + minutes) % 60;
h = (h + 1) % 24;
}
}
void Time::Display()
{
cout << "Time: " << h / 10 << h % 10 << ":" << m / 10 << m % 10 << endl;
}
int main()
{
Time list[4];
list[0] = Time(23, 59);
list[1] = Time(10, 30);
list[2] = Time(12, 50);
list[3] = Time(15, 30);
for (int i = 0; i < 4; i++)
{
list[i].Display();
}
cout << "Add 15 minutes to all values" << endl;
for (int i = 0; i < 4; i++)
{
list[i].AddMinutes(15);
list[i].Display();
}
cout << endl;
return 0;
}
Comments
Leave a comment