// This is the sample solution for SYSC 2002 lab #1 version #2 (D2) #include "stdstuff.h" #include "Date.h" int main () { Date birthDate, readDate, sentinelDate(31,12,1900); int days, day, bday, bmonth, byear, rday, rmonth, ryear; // prompt for, read in, and output today's date cout << "Enter your birth date (DD MM YYYY): "; birthDate.read(cin); cout << "Your birth date is: "; birthDate.write(cout); cout << "\n"; // or use endl // calculate day of week cout << "You were born on a "; day = birthDate.dayInWeek(); if (day==1) cout << "Monday.\n\n"; else if (day==2) cout << "Tuesday.\n\n"; else if (day==3) cout << "Wednesday.\n\n"; else if (day==4) cout << "Thursday.\n\n"; else if (day==5) cout << "Friday.\n\n"; else if (day==6) cout << "Saturday.\n\n"; else cout << "Sunday.\n\n"; // get birth date d, m and y for use later birthDate.getDDMMYYYY(bday, bmonth, byear); for (;;) { // prompt for and read in another date (use 31 12 1900 to quit) cout << "Enter another date (DD MM YYYY; 31 12 1900 to quit): "; readDate.read(cin); // break if sentinel date entered if (readDate.compareTo(sentinelDate)==0) break; // otherwise output the date cout << "You entered: "; readDate.write(cout); cout << "\n"; // find difference days = readDate.daysAfter(birthDate); cout << "On that date you will be " << days << " old.\n"; // check if same day of year readDate.getDDMMYYYY(rday, rmonth, ryear); // get d, m and y of read date // if same d and m, it's a birthday if ( (rday==bday) && (rmonth==bmonth) ) cout << "That date is your birthday.\n\n"; else cout << "That date is not your birthday.\n\n"; } pause(); return 0; }