// CS2310 Exercise 11 // // Name ______________________ SSN _______________ // // Chapter 14: p823 - 7, 8, 9, 11 // // In Chapter 11, we developed a TimeType class and a DateType Class // (page 625). Using composition, we want to create a TimeAndDay // class that contains both a TimeType object and a DateType object. // The public operations of the TimeAndDay class should be Set // (with six parameters to set the time and day), Increment, Write, // and a default constructor. Write a class declaration for the // TimeAndDay class. // // Implement the TimeAndDay default constructor. // // Implement the Set function of the TimeAndDay class. // // Implement the Write function of the TimeAndDay class. // //*********************************** // SPECIFICATION FILE (timedate.h) // This file gives the specifications // of TimeType, DateType and TimeAndDay // abstract data type //*********************************** class TimeType { public: void Set( /* in */ int hours, /* in */ int minutes, /* in */ int seconds ); // Precondition: // 0 <= hours <= 23 && // 0 <= minutes <= 59 && // 0 <= seconds <= 59 // Postcondition: // Time is set according to the incoming parameters void Write() const; // Postcondition: // Time has been output in the form HH:MM:SS TimeType(); // Postcondition: // Class object is constructed && Time is 0:0:0 private: int hrs; int mins; int secs; }; class DateType { public: void Set( /* in */ int newMonth, /* in */ int newDay, /* in */ int newYear ); // Precondition: // 1 <= newMonth <= 12 && // 1 <= newDay <= maximum no. of days in mon newMonth && // newYear > 1582 // Postcondition: // Date is set according to the incoming parameters void Print() const; // Postcondition: // Date has been output in the form // month day, year // where the name of the month is printed as a string DateType(); // New DateType object is constructed with a // month, day, and year of 1, 1, and 1583 private: int mo; int day; int yr; }; class TimeAndDay { public: void Set( /* in */ int hours, /* in */ int minutes, /* in */ int seconds, /* in */ int newMonth, /* in */ int newDay, /* in */ int newYear ); // Precondition: // 0 <= hours <= 23 && // 0 <= minutes <= 59 && // 0 <= seconds <= 59 && // 1 <= newMonth <= 12 && // 1 <= newDay <= maximum no. of days in mon newMonth && // newYear > 1582 // Postcondition: // Time and date are set according to the incoming parameters void Write() const; // Postcondition: // Time and date have been output in the form // HH:MM:SS month day, year TimeAndDay(); // New TimeAndDay object is constructed with a // time of 0:0:0 and a date of January 1, 1583 private: TimeType time; DateType date; };