Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider a class Time that represents a time of day. It attributes for the hour

ID: 3572159 • Letter: C

Question

Consider a class Time that represents a time of day. It attributes for the hour and minute. The hour value ranges from 0 to 23, where the range 0 to 11 represents a time before noon. The minute value ranges from 0 to 59.

A. Write a default constructor that initializes the time to 0 hours, 0 minutes.

B. Write a private method isVaild (hour, minute) that returns true if the given hour and minute values are in the appropriate range.

C. Write a method setTime (hour, minute) that sets the time if the given values are vaild.

D. Write another method setTime (hour, minute, isAM) that sets the time if the given values are vaild. The given hour should be in range 1 to 12. The parameter isAM true if the time is an a.m time and false otherwise.

Explanation / Answer

Hi, Please find my implementation of given functions.

Please let me know in case of any issue.


class Time{

private:
   int hour;
   int minute;

public:

   //A
   Time(){
       hour = 0;
       minute = 0;
   }

   //B
   bool isVaild(int hour, int minute){
       if(hour >=0 && hour <=23 && minute >=0 && minute <=59)
           return true;
       else
           return false;
   }

   //C
   void setTime(int hour, int minute){

       if(isVaild(hour, minute)){
           this->hour = hour;
           this->minute = minute;
       }
   }

   //D
   void setTime (int hour, int minute, bool isAM){

       if(hour>=1 && hour<=12 && minute>=0 && minute <=59 && isAM){
           this->hour = hour;
           this->minute = minute;
       }
   }

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote