// Lab Test #2 Version #2 #include "stdstuff.h" #include "Date.h" // This test involves writing an application program that uses the // Date class (Version 2 from Chapter 5). // Write your program in the space indicated below. // Run the sample executable provided if any of the instructions // here are unclear. // You may assume that all dates entered are reasonable, i.e. no // error checking of dates is required. // Note that program comments are required for full marks. // Your program is first to prompt the user for a birth date and // read it in. // Then your program is to loop repeatedly prompting the user for // dates, terminating when the user enters 1 1 2010. // For each date entered, you are to print out: // "You entered: dd/mm/yyyy" [where dd mm and yyyy are filled in appropriately] // "That date is the 1st day of the 2nd month." [where the day and month // are filled in appropriately, // i.e. 1st-31st for day and 1st-12th for month] // "You are xxxx days old on that date." [where xxxx is filled in appropriately] // "The date 10 days after that date is: dd/mm/yyyy" [where dd mm and yyyy // are filled in appropriately] // Again, run the sample executable if any of the above is unclear. int main() { String2002 dates[32] = {"unused", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st"}; // it is recommended, but not required, that you // use the above array of String2002 objects in // your solution Date adate, birthdate, sentinel(1,1,2010); int d, m, y; // for extracting day, month and year from a date // prompt for and read in a birth date cout << "Enter birth date (DD MM YYYY): "; birthdate.read(cin); cout << endl; for(;;) { // loop until date in future entered // prompt for and read in a date cout << "Enter a date (DD MM YYYY; 1 1 2010 to exit): "; adate.read(cin); // if date entered is 1 1 2010 (sentinel date) exit if (adate.compareTo(sentinel)==0) // or use daysAfter break; // output the date cout << "You entered: "; adate.write(cout); cout << endl; // get day and month adate.getDDMMYYYY(d,m,y); // extract day, month and year from birth date cout << "That date is the " << dates[d] << " day of the " << dates[m] << " month.\n"; // output number of days old cout << "You are " << adate.daysAfter(birthdate) << " days old on that date.\n"; // output the date in 10 days adate.move(10); // could use a constant cout << "The date 10 days after that date is: "; adate.write(cout); cout << "\n\n"; } // end for pause(); return 0; }