+ - hour: Add and subtract a number of seconds.
- Add parameter bool localtime to now() and today()
- String: Boundary checking on index and subtring operators
- Ported class Integer from the Gnu libg++ library.
seconds = sec;
}
+ hour(long sec)
+ {
+ hours = sec / 3600;
+ minutes = sec / 60 % 60;
+ seconds = sec % 60;
+ }
+
hour(String s);
bool proper(); // Check wether this is a proper clock time
}
friend hour operator+(hour, hour);
+ friend hour operator+(hour, long);
hour operator += (hour h);
hour operator ++ () // prefix
}
friend hour operator-(hour, hour);
+ friend hour operator-(hour, long);
hour operator -= (hour h);
hour operator -- () // prefix
return t;
}
+hour operator+(hour t1, long sec)
+{
+ long s; // Seconds
+
+ s = t1.hours * 3600 + t1.minutes * 60 + t1.seconds;
+ s += sec;
+
+ hour t(s);
+
+ return t;
+}
+
hour hour::operator+=(hour t)
{
seconds += t.seconds;
return t;
}
+hour operator-(hour t1, long sec)
+{
+ long s; // Seconds
+
+ s = t1.hours * 3600 + t1.minutes * 60 + t1.seconds;
+ s -= sec;
+
+ hour t(s);
+
+ return t;
+}
+
hour hour::operator-=(hour t)
{
seconds -= t.seconds;
std::cout << h6 << "\n";
assert(h6 == hour(21, 59, 59));
+ // Adding an integer number of seconds
+
+ hour h7(14, 22, 45);
+ long s7 = 7000;
+ hour h8;
+
+ h8 = h7 + s7;
+ std::cout << h7 << " + " << s7 << " seconds = " << h8 << "\n";
+ assert(h8 == hour(16, 19, 25));
+
+ std::cout << h7 << " += " << s7 << " seconds = ";
+ h7 += s7;
+ std::cout << h7 << "\n";
+ assert(h7 == hour(16, 19, 25));
+
+ // Subtracting an integer number of seconds
+
+ hour h11(14, 22, 45);
+ long s11 = 7000;
+ hour h12;
+
+ h12 = h11 - s11;
+ std::cout << h11 << " - " << s11 << " seconds = " << h12 << "\n";
+ assert(h12 == hour(12, 26, 05));
+
+ std::cout << h11 << " -= " << s11 << " seconds = ";
+ h11 -= s11;
+ std::cout << h11 << "\n";
+ assert(h11 == hour(12, 26, 05));
+
return 0;
}
++22:59:59 = 23:00:00
22:00:00-- = 21:59:59
--22:00:00 = 21:59:59
+14:22:45 + 7000 seconds = 16:19:25
+14:22:45 += 7000 seconds = 16:19:25
+14:22:45 - 7000 seconds = 12:26:05
+14:22:45 -= 7000 seconds = 12:26:05
PASS hour_arithmetic (exit status: 0)
assert(h4.Minute() == 20);
assert(h4.Second() == 45);
+ int seconds = 5000;
+ hour h5(seconds);
+
+ std::cout << seconds << " seconds = " << h5 << "\n";
+ assert(h5.Hour() == 1);
+ assert(h5.Minute() == 23);
+ assert(h5.Second() == 20);
+
return 0;
}
Contructor with hour = 88 minute = 55, and second = 1000: "88:55:1000"
Copy contructor from 15:20:45: "15:20:45"
Assigned from 15:20:45: "15:20:45"
+5000 seconds = 01:23:20
PASS hour_assign (exit status: 0)