CS 157 Spring 2003                Assignment 6 – More Control                                  .                               100 points

 

Assigned: 02/26/2003

Due: 03/12/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program!!!

 

Main Assignment:

We are writing a program to determine if a February date is valid or not.  Your program will ask the user for the year and day in question (being checked).  In order to always get the answer exactly right (which you should always do!), you need to consider leap years. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not 400. For example, the year 2003 is not a leap year, but 2004 is. 1900 is not a leap year, but 2000 is.

If the user’s year entered is invalid, display an error message instead of trying to go further. A year prior to 1582 (when Gregorian calendar was adopted) is invalid. As you should know, during a leap year, February dates should be from 1 to 29, and in other years dates should be from 1 to 28. 

See some examples below (Note that since your program is branching, you will need to test several times to know if your program is completely working!!!).  The examples below are NOT a complete test; try others too.

Put your name, e-mail address, and date in comments near the top.  Put comments in your program explaining what it does. Compile the program and remove any errors. Ensure that the program runs correctly. It should run correctly on any dates entered (if dates are invalid, running correctly means complaining about that).

                To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Samples:

1.

Determining if February Date is Valid

What year?

1999

What day?

34

I'm sorry February 1999 doesn't have that day! 34

2.

Determining if February Date is Valid

What year?

2000

What day?

29

This is a valid day for February 2000: 29

3.

Determining if February Date is Valid

What year?

2001

What day?

29

I'm sorry February 2001 doesn't have that day! 29

4.

Determining if February Date is Valid

What year?

1256

Bad year, sorry!

 

Hand in: