Programming Assignment 3

 

1.  Write prog03a.cpp which does the following things:

 

   1.      Opens an input file called prog03a.dat and an output file called prog03a.out.

 

   2.      Reads three integer numbers from the input file.

 

   3.      Write

                        a.            the three numbers

                        b.            the sum of the three numbers

c.                   the product of the three numbers

d.                  a statement telling the user which of the three numbers is the largest

            to the output file.

 

 

Make sure your program is running correctly and producing nice looking output.

 

2.  Now write prog03b.cpp which calculates the date on which Easter falls.

 

The date for any Easter Sunday can be computed as follows (all variables are integers):

 

   1.      Prompt the user and read in the year for which the date of Easter is wanted.

 

   2.      Do the following calculation.

                        Let a be the remainder from dividing year by 19

                        Let b be the remainder from dividing year by 4

                        Let c be the remainder from dividing year by 7

                        Let d be (19 * a + 24) % 30

                        Let e be (2 * b + 4 * c + 6 * d + 5) % 7

 

   3.      Then the date for Easter Sunday is March (22 + d + e).  Note that this formula can give a date in April if the value of (22 +d + e) is greater than 31.  You should print the correct date.  For example, if the date comes out as 28 print March 28; if the date comes out as 33 print April 2.

 

Write your program so that it will read the year from the key­board and write the date for Easter to the screen.  Be sure that you test dates which fall in March and in April.  For example:

 

            Enter the year

            1992

            Easter is Sunday, April 19 in 1992

                     

            Enter the year

            1991

            Easter is Sunday, March 31 in 1991

 

 

This algorithm works correctly for any year from 1900 to 2099 with the exception of 4 years.  These are 1954, 1981, 2049, and 2076.  In each of these years the date produced is 7 days later than it should be.  (Don’t worry about this problem.  If statements could be used to fix this.  We'll fix it in the next program.)

 

When your program is working correctly, use it to find the date for Easter in 1999. 

 

 


Back to the Main Menu