CPE 101 - Spring 2011 - Lab #3

Due:  End of lab Friday (4/15/11)

Main Problem: What day of the Year is it?

This lab has two  parts to it, in order to understand that the same program can be written using the different techniques that you’ve learned so far in lecture: if statements, switch statements, [and you'll need a while statement]. The question is nearly the same as that in chapter 4 problem 7 of your textbook.  Feel free to collaborate with each other on this lab, but each person must turn in their own lab.
Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996, is day 366 since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it divisible by 400. Your program should accept the month, day, and year as integers. The program will output the day number to the user and then ask if they would like to continue converting days or exit.
Error Checking.
This program needs you to start thinking about error checking. Inputs for months and days are very limited. The year is not necessarily as important because technically there can always be that year sometime before or down the line (is a year less than zero of any concern?) Look closely at the sample run at the end of the lab and take into account all the different cases that are required to error (range) check.  Pay particular attention to these considerations: 
1.	Month between 1 and 12
2.	Day: depending on the month anywhere from 28 – 31 as the max
3.	Day: account for leap year when error checking February 
(*Don’t worry about incorrect character input, you should at least view the behavior of your program if you enter characters, but you don’t have to correct for that in this lab... unless you finish early, completely and fully understand, and want to do some extra research into how to accomplish such a thing in C.)

Part A:
    Name this part of the lab: lab3A.c   Solve this lab using only if-else statements and one while loop.
Part B:
   Name this part of the lab: lab3B.c   Now solve this lab using a switch statement rather than the if-else statements. 
HINT: For Part B some if-else statements will still be needed for the error checking but use the switch statement to do the main calculations.

Testing your lab

Sample Run:

Hello and Welcome

Enter a month number:  2
Enter a day of that month:  28
Enter the year:  1999
That is day 59 of that year!

Would you like to quit(y/n)?  n

Enter a month number:  12
Enter a day of that month:  31
Enter the year:  1995
That is day 365 of that year!

Would you like to quit(y/n)?  n

Enter a month number:  12
Enter a day of that month:  31
Enter the year:  1996
That is day 366 of that year!

Would you like to quit(y/n)?  n

Enter a month number:  1
Enter a day of that month:  1
Enter the year:  2000
That is day 1 of that year!

Would you like to quit(y/n)?  n

Enter a month number:  19
Enter a day of that month:  23
Enter the year:  2000
Error there are only 12 months in any year

Would you like to quit(y/n)?  n

Enter a month number:  10
Enter a day of that month:  32
Enter the year:  1000
Error: no month has more than 31 days

Would you like to quit(y/n)?  n

Enter a month number:  4
Enter a day of that month:  31
Enter the year:  2009
Error: that month only has 30 days

Would you like to quit(y/n)?  n

Enter a month number:  2
Enter a day of that month:  30
Enter the year:  2000
Error: its a leap year, so that month has 29 days
Would you like to quit(y/n)?  y

Devise your own tests

The sample run above  gives you a lot of information about what your program must do, but it does not fully test the input-output relationship for the entire domain of possible inputs (does it?)   If you could test every possible input, you would need a way to check the given output to make sure it was correct (this is often called an "oracle" because it represents some method of obtaining the correct output given the input.... not always easy to do with complex programs.)    Devise a few of your own simple tests for some relatively suspicious cases that the sample run has not covered (design them to find odd problems or to exhibit the boundary cases where problems often occur.)  

Handin Instructions

Your submission should have the following header at the top:

	/*
	 * Name:  John Doe
	 * Assignment:  Lab 2
	 * Instructor:  
	 *
	 * Short description of your program......and 
	 * any notes about discrepancies or interesting behavior
	 * you've seen.
 */ 

Hand in the following files:

	lab3A.c
	lab3B.c

	handin instructor 101_lab3 lab3A.c lab3B.c

Gene Fisher	gfisher	
John Seng	jseng	
Clark Turner	csturner