//============================================================ // HOMEWORK 2 //------------------------------------------------------------ // DUE DATE: Monday, 3/6/2006 //============================================================ // // Below is the outline for the declaration and implementation // of a class Time. Note that this is very similar to the // example of the class Date we discussed during class. // // Complete the missing parts by: // // - Adding necessary datafields // // - Implementing the constructors // // - Implementing the function "bool IsBefore(Time t)" // that receives one Time object t and compares if // the object for which the method was called happens // to occur before the time t. // // - Implementing the member function Read() // that asks the user to enter all data // for the object and stores it in the data fields // // - EXTRA CREDIT // write a member function "int SecondsLaterThan(Time t)" // that computes how many seconds the current Time object // is than t - the time object that was passed as a parameter #include #include using namespace std; //------------------------------------------------------------ // class declaration for class Time // class Time { private: // ADD DATAFIELDS public: //Constructors Time(); Time(double h, double m, double s, string am_pm); //Data Access Functions //Task Functions void Read(); bool IsBefore(Time t); }; // - - - - - - - - - - - - - - - - - - - - // class implementation for class Time // // WRITE THE IMPLENTATIONS FOR ALL THE MEMBER FUNCTIONS // OF THE CLASS Time HERE //Constructors Time::Time() // Default Constructor { // WRITE PROGRAM CODE HERE } Time::Time(double h, double m, double s, string am_pm) { // WRITE PROGRAM CODE HERE } // TASK FUNCTIONS void Time::Read() { // WRITE PROGRAM CODE HERE } bool Time::IsBefore(Time t) { // WRITE PROGRAM CODE HERE }; //============================================================ // main program // int main() { Time t1(8,15,6,"PM"); Time t2; t2.Read(); // let user enter the time for t2 if (t2.IsBefore(t1)) { cout << "You are early!\n"; } else if (t1.IsBefore(t2)) { cout << "You are late!\n"; } else { cout << "You are just on time!\n"; } }