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

MUST BE IN C++ LANGUAGE. NO BUILT IN FUNCTIONS. CAN ONLY USE <IOSTREAM>!!!!*****

ID: 3830420 • Letter: M

Question

MUST BE IN C++ LANGUAGE. NO BUILT IN FUNCTIONS. CAN ONLY USE <IOSTREAM>!!!!******* You may not use any header files other than iostream or any built-in functions.**

For this assignment you are to design and implement a class Time. Objects of this class are intended to represent time values that are viewed as consisting of an hour, minute, and second values. The values associated with a Time object can range between 00:00:00 (midnight) and 23:59:59, inclusively. The public interface for this class should consist of the following sets of functions:

Constructors:

Time():

This function defines a default initial value of 00:00:00 for a Time object.

Time(int h, int m, int s):

This function initializes a Time object so that its hours is h, its minutes is m, and its seconds is s. The parameters that correspond to the minutes and seconds should be specified with a default value of 0.

Access Functions:

int getHours() const;

Returns the hours value of a Time object.

int getMinutes() const;

Returns the minutes value of a Time object.

int getSeconds() const;

Returns the seconds value of a Time object.

bool LessThan(Time) const;

For two Time objects t1 and t2, t1.LessThan(t2) returns true if t1 is less than, or comes before t2.

bool GreaterThan(Time) const;

For two Time objects t1 and t2, t1.GreaterThan(t2) returns true if t1 is greater than, or comes after t2.

bool EqualTo(Time) const;

For two Time objects t1 and t2, t1.EqualTo(t2) returns true if t1 is equal to, or is the same time as t2.

Modifier Functions:

void setHours(int h);

Set the hours of Time object to value specified by h.

void setMinutes(int m);

Set the minutes of Time object to value specified by m.

void setSeconds(int s);

Set the seconds of Time object to value specified by s.

void setTime(int h, int m, int s);

Set the hours, minutes and seconds of a Time object to the values specified by h, m and s, respectively. The parameters corresponding to the minutes and seconds value should have default values of 0.

Input/Output Functions:

void Read();

t1.Read(); accepts from the keyboard a time value for t1 that is input in the form hh:mm:ss.

void Write();

t1.Write(); outputs to the display the value of t1 in the format hh:mm:ss.

Using the Time class you are to implement a well-designed program that includes two Time objects, say t1 and t2 (you may use other identifiers), where t1 is uninitialized and t2 is initialized to the value 12:45:35. The program should output the values of t1 and t2. Next the program should prompt the user to enter two values (one prompt for each), after which the program outputs these two values in ascending order, regardless of the order that the data was entered.

Explanation / Answer

#include <iostream.h>
#include <string>

using namespace std;

class Time {
    private:
        int hr;
        int min
        int sec;
    public:
      Time(){
          hr = 0;
          min = 0;
          sec = 0;
      }
      Time(int h, int m, int s){
          hr = h;
          min = m;
          sec = s;
      }
      int getHours(){
          return hr;
      }
      int getMinutes(){
          return min;
      }
      int getSeconds(){
          return sec;
      }
      void setHours(int h){
          hr = h;
      }
      void setMinutes(int m){
          min = m;
      }
      void setSeconds(int s){
          sec = s;
      }
      void setTime(int h, int m, int s){
          hr = h;
          min = m
          sec = s;
      }
      bool LessThan(Time t){
         if (hr < t.getHours())
            return true;
         if (hr == t.getHours()){
            if (min < t.getMinutes())
               return true;
            if (min == t.getMinutes()){
               if (sec < t.getSeconds())
                  return true;
            }
         }
         return false;            
      }
      bool GraeterThan(Time t){
         if (hr > t.getHours())
            return true;
         if (hr == t.getHours()){
            if (min > t.getMinutes())
               return true;
            if (min == t.getMinutes()){
               if (sec > t.getSeconds())
                  return true;
            }
         }
         return false;            
      }
      bool EqualTo(Time t){
         if (hr == t.getHours() && min == t.getMinutes() && sec == t.getSeconds())
            return true;
         return false;            
      }
      void Read(){
          string input;
          cout << "Enter value in hh:mm:ss format"
          cin >> input;
          hr = stoi(input.substr(0,2));
          min = stoi(input.substr(3,2));
          sec = stoi(input.substr(6,2));
      }
      void Write(){
        if (hr < 10)
           cout << "0" << hr << ":";
        else
           cout << hr << ":";
        if (min < 10)
           cout << "0" << min << ":";
        else
           cout << min << ":";
        if (sec < 10)
           cout << "0" << sec << ":";
        else
           cout << sec << ":" << endl;
       
      }
};

void main() {
     Time t1;
     Time t2(12,45,35);
     t1.Write();
     t2.Write();
     t1.Read();
     t2.Read();
     if (t1.LessThan(t2) || t1.EqualTo(t2)){
        t1.Write();
        t2.Write();
     }
     else {
        t2.Write();
        t1.Write();        
     }   
}

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