CS 246 Homework 2:  Functions and Program Design

You MUST work with one other person on this assignment.
This is a semi-partnered assignment (some parts will be done together, other parts will be done individually).


Step 1 (Program Design) Due:  In hard copy on Wednesday, February 13, 2013
Step 3 (Initial Implementations) Due:  Via e-mail on Tuesday, February 19, 2013
 (you are encouraged to arrange an earlier deadline with your partner)

Step 5 (Full Assignment) Due:  Friday, February 22, 2013
 
Please read the homework guidelines before you proceed.  This is a more complex assignment.  Be sure to read all steps before starting, and complete them in-order.

The purpose of this assignment is to get you comfortable with: (1) planning out your program before implementation, and (2) developing code separately for integration.


Assignment Description:  Perpetual Calendar

Write a C++ program that displays a Gregorian calendar for any year. Essentially, you are implementing the Unix 'cal' command. Actually the Gregorian calendar was not adopted in Europe until 1582, and not until 1752 in Britain (If you check with the Unix 'cal' command, you will see that the 11 days between 9/3/1752 and 9/13/1752 are missing.) The Julian calendar was used before that in Christian countries, and the Gregorian didn't become the world standard until the 1900 on. For the purpose of this program though, we are still going to display a Gregorian calendar for every year 1-9999 A.D.

Here's an algorithm for calculating the calendar:

  1. Find the day of the week a year starts on.

    In general, for every year that is not a leap year, next year starts one day later in the week. For every year that is a leap year, next year starts two days later in the week.

    2012 starts on a Sunday. Count backwards (substract) for any year before 2012 following the same rule.

    Rules for deciding a leap year:


  2. Determine the days in a month. January, March, May, July, August, October and December each have 31 days, Febuary has 28 days if the current year is not a leap year, 29 if it is. All other months have 30 days.
  3. Now that you have the day of the week the year starts on, and the number of days in any month, you can find out the day of the week each month starts on. Indent (print white spaces) accordingly, and you have the correct calendar.

Your program must do the following:

Copy the executable ~eeaton/public/cs246/calndr and run it to get an idea how your program should behave.  Your program should duplicate the same user interaction (i.e., prompt the user to enter a year, then prompt them for a month, then exit once you print the requested calendar.)

Also check out the unix shell command cal


Step 1:  Program Design (Partnered work)

For this homework, a program design is required from each group. A program design is a document containing skeleton code that represents the implementation of your actual program. All functions are represented by prototypes only, except for main(), which should be fleshed out with appropriate calls and local variable declarations.   You should not provide implementations for the functions, just function prototypes and appropriate header comments.

In the header comments for each function prototype,  tell me which member of the group will be responsible for implementing this function.  Divide the work evenly between all functions.

This part is due in hard copy on the due date above; you may either give it to me in class or slip a copy under my office door.

Put the function prototypes into a file called hw2_lastname1_lastname2.h and share it with your partner.

You must finish the program design and design write-up before proceeding to the next step.  Even if you make modifications to the program design in step 2, you should still turn in the program design determined in this step.

Step 2:  Initial Implementations (Individual work)

Implement each of the functions for which you're responsible.  Your partner will be doing the same for his or her functions.

During this step, you may NOT share or discuss your function implementations with your partner. 
Because you know the function prototypes that your partner is implementing, you can call those functions trusting that the implementation will work.  However, since you don't actually have their implementation, you will not be able to run your code to test it.  Therefore, you must use unit testing to test each part of your program independently of your partner's implementation.

You may talk to your partner about the interface (i.e., the function prototypes, adding or deleting functions, etc.)  During this step, you may make changes to the function prototypes and program design from step 1 in consultation with your partner.

Save your implementation as a file called hw2_lastname.cpp (substituting in your last name).

Step 3: Submit Initial Implementations (Partnered work)

Once both partners have finished step 2, share your implementation with your partner. 

Without changing the implementations at all, put the two implementations into a directory called hw2-initial_lastname1_lastname2 and package them up into a single gzip'ed tar file named hw2-initial_lastname1_lastname2.tar.gz

E-mail this gzip'ed tar file to your professor in an e-mail with the subject "CS246:  HW2-initial Lastname1 Lastname2".
 

Step 4:  Final Implementation (Individual work)

From this point on, you will work individually.  You may not discuss your implementation, your partner's implementation, or the program design any further with your partner.

Combine your partner's implementation with your own to create a working perpetual calendar program.

Keep the two source files separate (i.e., you should have two .cpp files:  hw2_yourlastname.cpp that contains the main() function and the implementations of your functions and hw2_partnerslastname.cpp that contains your partner's implementation.)

Although you may modify anything to make it work (including the function implementations provided by your partner), try to modify as little code as possible.


Step 5:  Submit Final Implementation (Individual work)

Submit your working calendar program, following the assignment guidelines and submission instructions. 

Be sure to list your partner's name in your README file.

Be sure to include an example compilation command in your README file.

In addition to the electronic submission of your program, hand in a write-up with three sections:
1.) A discussion of how and why your final implementation differs from your program design, if at all.
2.) A discussion of how and why you had to modify your initial implemenation to make the assignment work, if at all
3.) A discussion of how and why you had to modify your partner's initial implemenation to make the assignment work, if at all. 
You can include this write-up in your README file.

Hand in the write-up in hard copy along with the hardcopy printouts of your code.


Grading

Your grade will be based on: