Answer to Question #299902 in C++ for ishara

Question #299902

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.


1
Expert's answer
2022-02-20T07:00:48-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog