#include <iostream>
class Time {
private:
int totalMinutes;
public:
// Constructor that takes one integer parameter, a time in minutes.
Time(int minutes = 0) : totalMinutes(minutes) {}
// Constructor that takes two integer parameters, a number of hours and a number of minutes.
Time(int hours, int minutes) {
set(hours, minutes);
}
// set method that takes two integer parameters, a number of hours and a number of minutes.
void set(int hours, int minutes) {
totalMinutes = hours * 60 + minutes;
}
// getMinutes method returns the time as all minutes.
int getMinutes() const {
return totalMinutes;
}
// getWholeHours method returns the number of whole hours.
int getWholeHours() const {
return totalMinutes / 60;
}
// getHours method returns the time in hours as a double.
double getHours() const {
return static_cast<double>(totalMinutes) / 60;
}
// getRemainingMinutes returns the number of minutes after accounting for the whole hours.
int getRemainingMinutes() const {
return totalMinutes % 60;
}
// add method returns the calling time plus the parameter time.
Time add(const Time &other) const {
return Time(totalMinutes + other.totalMinutes);
}
};
int main() {
// Create several time objects and test the various class methods.
Time t1(135); // 135 minutes
Time t2(2, 15); // 2 hours and 15 minutes
Time t3(1, 45); // 1 hour and 45 minutes
Time t4 = t2.add(t3); // t2 + t3
// Test the methods
std::cout << "t1 total minutes: " << t1.getMinutes() << std::endl;
std::cout << "t1 whole hours: " << t1.getWholeHours() << std::endl;
std::cout << "t1 remaining minutes: " << t1.getRemainingMinutes() << std::endl;
std::cout << "t1 hours (as double): " << t1.getHours() << std::endl;
std::cout << "t2 total minutes: " << t2.getMinutes() << std::endl;
std::cout << "t2 whole hours: " << t2.getWholeHours() << std::endl;
std::cout << "t2 remaining minutes: " << t2.getRemainingMinutes() << std::endl;
std::cout << "t2 hours (as double): " << t2.getHours() << std::endl;
std::cout << "t3 total minutes: " << t3.getMinutes() << std::endl;
std::cout << "t3 whole hours: " << t3.getWholeHours() << std::endl;
std::cout << "t3 remaining minutes: " << t3.getRemainingMinutes() << std::endl;
std::cout << "t3 hours (as double): " << t3.getHours() << std::endl;
std::cout << "t4 (t2 + t3) total minutes: " << t4.getMinutes() << std::endl;
std::cout << "t4 whole hours: " << t4.getWholeHours() << std::endl;
std::cout << "t4 remaining minutes: " << t4.getRemainingMinutes() << std::endl;
std::cout << "t4 hours (as double): " << t4.getHours() << std::endl;
return 0;
}