< previous page page_250 next page >

Page 250
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
One very simple formula computes the day of the week from a given Julian day:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Day of the week = (Julian day + 1) % 7
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
where % is the C++ modulus operator. This formula gives a result of 0 for Sunday, 1 for Monday, and so on up to 6 for Saturday. For Julian day 2435763, the result is 2 (a Tuesday). Your job is to write a C++ program that inputs a Julian day, computes the day of the week using the formula, and then prints out the name of the day that corresponds to that number. If the maximum int value on your machine is small (32767, for instance), use the long data type instead of int. Be sure to echo-print the input data and to use proper indentation and comments.
Your output might look like this:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Enter a Julian day number:
2451545
Julian day number 2451545 is a Saturday.
3. You can compute the date for any Easter Sunday from 1982 to 2048 as follows (all variables are of type int):
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a is year % 19
b is year % 4
c is year % 7
d is (19 * a + 24) % 30
e is (2 * b + 4 * c + 6 * d + 5) % 7
Easter Sunday is March (22 + d + e)*
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Write a program that inputs the year and outputs the date (month and day) of Easter Sunday for that year. Echo-print the input as part of the output. For example:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Enter the year (for example, 1997):
1985
Easter is Sunday, April 7, in 1985.
4. The algorithm for computing the date of Easter can be extended easily to work with any year from 1900 to 2099. There are four years, 1954, 1981, 2049, and 2076, for which the algorithm gives a date that is seven days later than it should be. Modify the program for Problem 3 to check for these years and subtract 7 from the day of the month. This correction does not cause the month to change. Be sure to change the documentation for the program to reflect its broadened capabilities.
5. Write a C++ program that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two data items. The first is a characterD (for diameter), C (for circumference), or A (for area)to indicate the calculation needed. The next data value is a floating point number
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
*Notice that this formula can give a date in April.

 
< previous page page_250 next page >