Create a class called Time that includes three instance variables: hour (int), minute (int) and second (int). Provide following constructors to initializes the three instance variables.
• No-argument constructor: Initializes each instance variable to zero.
• Constructor: hour supplied, minute and second defaulted to 0.
• Constructor: hour and minute supplied, second defaulted to 0.
• Constructor: hour, minute and second supplied.
• Constructor: Another Time2 object supplied.
#include <iostream>
using namespace std;
class Time {
public:
Time(): hour(0), m_minute(0), m_second(0) {}
Time(int hour): m_hour(hour), m_minute(0), m_second(0) {}
Time(int hour, int minute): m_hour(hour), m_minute(minute), m_second(0) {}
Time(int hour, int minute, int second): m_hour(hour), m_minute(minute), m_second(second) {}
Time(const Time& time): m_hour(time->hour), m_minute(time->minute), m_second(time->second) {}
private:
int m_hour;
int m_minute;
int m_second;
};
int main() {
Time time(12, 34);
return 0;
}
Comments
Leave a comment