C++ Homework Write a Time for Class.

huojian
ProgrammingAssignment4.pdf

Object-Oriented Programming I Fall 2018 CIS 3100

Programming Assignment 4 For this assignment you are to create a class Time for representing time values. Objects of this class are intended to represent time values that are viewed as consisting of an hour, minute, and second values. The value 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. If an invalid initial value is specified, then the time value should be set to 00:00:00.

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, or 0 if h is invalid. void setMinutes(int m);

Set the minutes of Time object to value specified by m, or 0 if m is invalid. void setSeconds(int s);

Set the seconds of Time object to value specified by s, or 0 if s is invalid. 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. If an invalid initial value is specified, then the time value should be set to 00:00:00.

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.

void Write12(); t1.Write(); outputs to the display the value of t1 in the 12 hour format hh:mm:ss AM/PM. That is, the value of hh ranges from 00 to 12, and the time value includes an AM or PM designator. For example, 9:45:15 PM. 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 10:56: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. Due Date: November 20, 2018

  • Object-Oriented Programming I Fall 2018
    • Programming Assignment 4