Classwork 13: Top-Down Design

Objectives

To complete the top-down design process by implementing the functions outlined in the annual calendar program designed in the previous class.

Assignment

The class will be divided into two teams — one led by Prof. Chang and one by lab assistant Josh Poole. We will use CVS to handle version control and organize the submissions.

Step 1: CVS Demo

Before proceeding, pay attention to the CVS demonstration.

Step 2: Checkout

To begin using CVS, you must first "checkout" a module. Use one of the following commands, depending on whether you are on teamChang or teamJosh:

cvs -d /afs/umbc.edu/users/c/h/chang/pub/calendar/ checkout teamChang

or

cvs -d /afs/umbc.edu/users/c/h/chang/pub/calendar/ checkout teamJosh

This will create a sub-directory in your account named teamChang or teamJosh and will copy the initial files into the subdirectory. You will do all your work in that subdirectory, so:

cd teamChang

or

cd teamJosh

A listing in the directory should show the files:


calendar.c  days_in_month.c  leap_year.c
calendar.h  find_next_dow.c  print_heading.c
CVS         jan1_dow.c       print_month.c

The main function is in calendar.c:

/* File: calendar.c * * Prints out an annual calendar for the year specified by user. */ #include <stdio.h> #include "calendar.h" int main() { int year ; int month ; // DoW = "Day of Week" int startingDoW ; // this month starts on Sun = 0, Mon = 1, ..., Sat = 6 ? int leapYear ; // 1 = this year is a leap year, 0 = not int numberOfDays ; printf("This program prints out an annual calendar.\n") ; printf("Enter year: ") ; scanf("%d", &year) ; // Should we check that year is after 1582? // 1583 = first full year of Gregorain calendar leapYear = IsLeapYear(year) ; // Find the day of week for January 1 of this year startingDoW = Jan1DoW(year) ; for (month = 1 ; month <= 12 ; month++) { PrintHeading(month, year) ; numberOfDays = DaysInMonth(month, leapYear) ; PrintMonth(startingDoW, numberOfDays) ; // Find the day of week for the 1st day of the next month startingDoW = FindNextDoW(startingDoW, numberOfDays) ; } return 0 ; }

You can compile the entire program using:

gcc -Wall *.c

However, the functions in the other files are just "stubs" and do not do what they are supposed to do (yet). For example, DaysInMonth() always returns 30 days:

/* File: days_in_month.c * * Implements DaysInMonth */ #include "calendar.h" // // Returns the number of days in the specified month. // // January = 1, February = 2, ..., December = 12 // // Parameter leapYear = 1 if leap year, // leapYear = 0 if not int DaysInMonth(int month, int leapYear) { return 30 ; }

Thus, when you run the program it does not do very much, but at least you have a program that compiles and runs:

linux2% ./a.out
This program prints out an annual calendar.
Enter year: 2012
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
    xxxxx xxxx
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
linux2% 

Step 3: Get a Part

Discuss with the rest of your team and your team leader who will implement which part. Break up into sub-teams of 2 or 3 students. Each sub-team will work with one of the functions that has to be implemented.

You should only edit the file that you are assigned. You can test your function by compiling the entire program, but you should not edit the other files.

Step 4: Implement Your Part

With your sub-teammate(s) implement your assigned function. Thoroughly test your part before submitting. To submit a new version, you must type in the following CVS commands

cvs update
cvs commit -m "student1 student2 student3"

Here you should replace student1 student2 student3 with the names of the students in the sub-team. These are just commments, but it helps us determine who submitted the update.

After you have submitted an update, holler and let the other people in your team know that a new version has been submitted.

Step 5: Getting Updates

When other people in your team submit an update, you can update your own copy of the program from the CVS repository simply by typing:

cvs update

Step 6: Testing

If you have finished implementing your part, continue updating your copy. Test the main program with the latest version of each part. Now you are concerned that your part might not work correctly with new versions of the parts implemented by other students. When this happens you have to discuss the problem with the other students and determine who has to change which part. So, you are not off the hook until the entire program works correctly.

Submitting

There is nothing to submit using the submit command since we worked with CVS. Make sure that you entered the names of your sub-teammates after the -m option of cvs commit. You can check this using:

cvs log filename

where filename is the name of the file you worked with. For example, if you worked with leap_year.c then you can check your submission with:

cvs log leap_year.c