1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
// The only header files that you may use for this assignment are
// iostream, and iomanip, which can be used for formatting data if you
// are familiar with it.
#include <iostream>
#include <iomanip>
// 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.
class Time {
// The public interface for this class should consist of the
// following sets of functions:
public:
// Constructors:
// Time(): This function defines a default initial value of
// 00:00:00 for a Time object.
Time();
// 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.
Time(int h, int m, int s);
// Access Functions:
// Returns the hours value of a Time object.
int getHours() const;
// Returns the minutes value of a Time object.
int getMinutes() const;
// Returns the seconds value of a Time object.
int getSeconds() const;
// For two Time objects t1 and t2, t1.LessThan(t2) returns true if
// t1 is less than, or comes before t2.
bool LessThan(Time);
// For two Time objects t1 and t2, t1.GreaterThan(t2) returns true
// if t1 is greater than, or comes after t2.
bool GreaterThan(Time);
// For two Time objects t1 and t2, t1.EqualTo(t2) returns true if
// t1 is equal to, or is the same time as t2.
bool EqualTo(Time);
// Modifier Functions:
// Set the hours of Time object to value specified by h.
void setHours(int h);
// Set the minutes of Time object to value specified bym.
void setMinutes(int m);
// Set the seconds of Time object to value specified by s.
void setSeconds(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.
void setTime(int h, int m, int s);
// Input/Output Functions:
// t1.Read(); accepts from the keyboard a time value for t1 that
// is input in the form hh:mm:ss.
void Read();
// t1.Write(); outputs to the display the value of t1 in the
// format hh:mm:ss.
void write();
};
int main()
{
// Using the Time class you are to implement a well-designed
// program that can be used for sorting a sequence of up to 100
// Time object values.
// The program should be begin by asking the user to specify the
// number of values to be sorted.
// Once a valid value, say n, has been input, the program should
// then prompt the user to enter n time values.
// Once all n values have been entered, the program should sort
// them in ascending order
// and then output them, one per line.
}
// I may also provide you with a main() function to be used to
// test your Time class implementation.
|