// Lab Test #2 Version #1 #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 today's date and // read it in. // Then your program is to loop repeatedly prompting the user for // birth dates, terminating when the user enters today's date again // (i.e. the same date as the first date entered). // For each date entered, you are to print out: // "You entered: dd/mm/yyyy" [where dd mm and yyyy are filled in appropriately] // "You were born on a Monday." [where the day is Monday, Tuesday, ..., Sunday, // as appropriate] // "You were born during the summer." [if the month is June, July or August] // or "You were not born during the summer." [if the month is not June, July // or August] // "You are xxxx days old today." [where xxxx is filled in appropriately] // Again, run the sample executable if any of the above is unclear. int main() { String2002 days[8] = {"unused", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; // it is recommended, but not required, that you // use the above array of String2002 objects in // your solution Date today, bdate; int d, m, y; // for extracting day, month and year from a date // prompt for and read in today's date cout << "Enter today's date (DD MM YYYY): "; today.read(cin); cout << endl; for(;;) { // loop until date in future entered // prompt for and read in birth date cout << "Enter birth date (DD MM YYYY; today to exit): "; bdate.read(cin); // if date is today, exit if (bdate.compareTo(today)==0) // or use daysAfter break; // output the birth date cout << "You entered: "; bdate.write(cout); cout << endl; // calculate the day in the week using dayInWeek() as an index into // the String2002 array provided (ok if temporary variable used) cout << "You were born on a " << days[bdate.dayInWeek()] << ".\n"; // get month (and day and year, but we don't need them) bdate.getDDMMYYYY(d,m,y); if (m>=6 && m<=8) // month is June, July or August (6, 7, or 8) cout << "You were born during the summer.\n"; else cout << "You were not born during the summer.\n"; // output number of days old cout << "You are " << today.daysAfter(bdate) << " days old today.\n\n"; } // end for pause(); return 0; }