Exercise 6 Keeping track of dates in daymonth

  • Slides: 1
Download presentation
Exercise 6 Keeping track of dates in day/month format can be inconvenient, particularly when

Exercise 6 Keeping track of dates in day/month format can be inconvenient, particularly when it is necessary to do things like working out the number of days between two dates. For this reason, “day_numbers” are sometimes used instead. January 1 st of a year is day number 1, January 2 nd is day number 2, and so on. February 1 st is always day number 32, but March 1 st can be either day number 60 or day number 61, depending on whether we’re dealing with a leap year. Similarly, December 31 st can be either day 365 or day 366. Write a program which converts dates between day/month and day number format. The sample executable supplied should give the idea. Basic error checking is required. Years before 1500 should be treated as invalid, as should illegal day, month, and day number values. You need not worry about the possibility of non-numeric input, though you are of course welcome to make your program completely bulletproof. If you elect to go this way, you might want to examine the code supplied for assignment #5. To get you started, some handy functions have been supplied (see file skeleton. cpp). Your program must include a function which converts a day and a month to a day number, and another which converts a day number to a day and a month. Note that both functions are going to need to know which year they’re dealing with. Note also that the second function must “return” two values (call by reference time!). 1 ECOR 1606 Copyright © 2002, Department of Systems and Computer Engineering, Carleton University