School of Engineering and Applied Science
Department of Computer Science
CSci 49 -- Introduction to C Computing
http://www.seas.gwu.edu/~csci49/spring06
Prof. Michael B. Feldman 
mfeldman@gwu.edu

Project 7
Due Date: beginning of lecture, Wednesday, April 6, 2006

The goal of this project is to develop a mini-library of functions, and to use them in an application program.

Project:

We have reached the stage in the course where it's time to start writing our own functions. The objective in this project is to add some methods to a pre-existing mini-library DateOps, test these, then use the enhanced DateOps library to help you rewrite your calendar program from Project 6.

Part 1:

Copy and syntax-check the file DateOps.c. Use the command ccheck to do the checking.
Now copy, compile, and run DayTest.c, which includes and uses the library.
Now add the following functions to the DateOps library. DateOps already contains stubs (like little framework files), so you just need to fill in the function bodies
 
These function do NOT write any output to the console.

int isValid (int month, int day, int year)

Returns 1 if month, day, and year form a valid date whose year is no earlier than 1753, and 0 otherwise.

int daysInMonth (int month, int year)

Returns the number of days the month month has in the year year, or MAXINT if either parameter is out of range.

int dayOfWeek(int month, int day, int year)

Returns the day of the week (Sunday = 0, Monday = 1, etc.) for the given month/day/year combination, if that combination forms a valid date, or MAXINT otherwise.

This project is quite different from Projects 1-5. In the others, there was only a single application program, but in this one you are writing a library that provides a set of reusable functions. These functions could be imported into, and used by, any number of different applications.

So how do you test such a thing? Each function must be tested on its own, independently of the others. In effect, each function requires its own little test plan. You can choose to implement each little test plan with a separate test program, or you can write one larger main program that carries out a sequence of little test plans. That choice is up to you, but it must be clear from the test plans, the annotations on your turnin, and your test-program code, how each method is being tested on its own.

Part 2:

Now modify your program from Project 6 so as to use the functions from this library to the greatest extent possible. Also make two changes to the program:
  1. validate the input dates
  2. add the day name to each date written to the output file, e.g.,

  3. Wednesday, March 29, 2006
In validating the input date, give the user a chance to keep trying if (s)he enters an invalid date. For each of the two input dates, your program will have a loop that uses a boolean flag variable:

int validityFlag = 0;
while(validityFlag == 0)
{
  // prompt for oneMonth, oneDay, and oneYear
  if (isValid(oneMonth, oneDay, oneYear))
  {
    validityFlag = 1;
  }
  else
  {
    printf ("Invalid date; please try again.\n");
  }
}

What to submit:

You must follow the project preparation and submission documents on the website.

Your grade will be calculated on a 20-point basis, as follows:

Extra credit:

We'll continue the 2-point bonus for getting an early start. If you e-mail your "framework" listing file to Prof. Feldman, and the time stamp on the e-mail is no later than 5 PM, Monday, April 3, 2006, you will be awarded 2 extra project points. The "framework" must be a listing (.txt) file, with no compilation errors or warnings, that contains the declared variables, and a set of comments inserted for the main algorithm steps.

MBF 3/28/06