Due Wednesday, 1999/10/20
Read sections 5.8 through 5.10 in Deitel and Deitel.
Suppose you are interested in knowing the historical average temperature in Richmond. Fortunately, while rummaging around the Wayne Count Courthouse, you found a set of 1,176 monthly charts which continuously track the temperature at all times of the day from January, 1901 through December, 1998. You decide that if you pick 100 random dates and times, look up the temperature on the charts, and then average the temperatures together, you should get a pretty good approximation. Unfortunately, you don't have a calendar/clock randomizer to tell you which dates and times to use to look up the temperatures you need for your average. You need a program.
Write a program that generates 100 random date-time values between "1901/01/01 00:00:00" and "1998/12/31 23:59:59". Only generate valid dates and times, and make it possible for any valid date or time to be randomly generated. In other words, account for the different number of days in the various months, and for the differing numbers of days in February.
Your program should write one date-time per line. You may find the following printf statement helpful:
printf( "%04d/%02d/%02d %02d:%02d:%02d\n" ,
year , month , day , hour , minute , second ) ;
The output from your program should look something like this:
1926/06/17 11:28:05 1980/01/10 14:48:52 1907/11/22 13:47:26 1934/09/11 21:14:48 1977/02/24 03:22:19 . . .
Note that this program doesn't necessarily require that you define any new functions (beyond main()), but it does require that you use the rand() function. You should consider using the srand() and time() functions as suggested by the examples in Deitel and Deitel.
Copyright © 1999, Ray Ontko (rayo@ontko.com).