// 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. // //*********************************** // IMPLEMENTATION FILE (timedate.cpp) // This file gives the implementations // of member functions in TimeType, // DateType and TimeAndDay // abstract data types //*********************************** #include #include #include "timedate.h" using namespace std; void TimeType::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 hrs = hours; mins = minutes; secs = seconds; } void TimeType::Write() const { // Postcondition: // Time has been output in the form HH:MM:SS cout << hrs << ':' << mins << ':' << secs << endl; } TimeType::TimeType() { // Postcondition: // Class object is constructed && Time is 0:0:0 hrs = 0; mins = 0; secs = 0; } void DateType::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 mo = newMonth; day = newDay; yr = newYear; }; void DateType::Print() const { // Postcondition: // Date has been output in the form // month day, year // where the name of the month is printed as a string cout << mo << ' ' << day << ", " << yr << endl; } DateType::DateType() { // New DateType object is constructed with a // month, day, and year of 1, 1, and 1583 mo = 1; day = 1; yr = 1583; } void TimeAndDay::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 // write your implementation here } void TimeAndDay::Write() const { // Postcondition: // Time and date have been output in the form // HH:MM:SS month day, year // write your implementation here } TimeAndDay::TimeAndDay() { // New TimeAndDay object is constructed with a // time of 0:0:0 and a date of January 1, 1583 // write your implementation here } int main() { TimeAndDay timeday; timeday.Write(); timeday.Set(16, 50, 25, 9, 24, 2001); timeday.Write(); }