UMBC CMSC 201 Spring '05 CSEE | 201 | 201 S'05 | lectures | news | resources |discussion| help

Project 1 Design

Project 1 is composed of two modules Proj1 and Dates. Proj1 has the main function along with functions to print an initial greeting and to print a menu of user options. Dates has assorted function to manipulate and print date, calendars and associated values. For each of these two modules, we list the defined constants and the functions (comments and prototypes).


-- Proj1 ----------------------------------------------------------------

/* year related constants */
#define MIN_YEAR 1753
#define MAX_YEAR 9999

/* menu related constants */ #define MIN_CHOICE 1 #define MAX_CHOICE 6 #define PRINT_DAY 1 #define PRINT_MONTH 2 #define PRINT_YEAR 3 #define PRINT_INTERVAL 4 #define NEW_DATE 5 #define QUIT 6 /******************************************************************* * * AskMenu( ) prints the menu of user options, reads an integer * indicating the user's choice until a valid one is given, and * returns it. The range of a valid choice is from MIN-CHOICE to * MAX_CHOICE, inclusive. * * INPUTS: none * OUTPUT: an integer indicating the user's choice. * *******************************************************************/ int AskMenu (void); /******************************************************************* * * PrintGreeting( ) prints an initial message when the program starts. * * INPUTS: none * OUTPUT: none * *******************************************************************/ void PrintGreeting (void); /******************************************************************* * * main( ) prints a greeting, asks for an initial date (day, month * and year) and enters a loop to accept commands from the user and * execute them. The loop presents a menu using AskMenu( ) like * Options: * 1: Print Date * 2: Print Month * 3: Print Year * 4: Print days between this date and another * 5: Reset date * 6: Quit * and uses a switch to dispatch on the user's choice to perform * the selected task. * * INPUTS: none * OUTPUT: 0 * CALLS: AskMenu, GetYear, GetMonth, GetDay, PrintDate, PrintMonth, PrintYear * *******************************************************************/ -- dates ----------------------------------------------------------------- #define MIN_DAY_OF_WEEK 0 #define MAX_DAY_OF_WEEK 6 #define MIN_MONTH 1 #define MAX_MONTH 12 #define DAYS_IN_WEEK 7 /* December 31, 1752 was a Sunday */
#define ANCHOR_DAY 31
#define ANCHOR_MONTH 12
#define ANCHOR_YEAR 1752
#define ANCHOR_DAY_OF_WEEK 0 #define SUNDAY 0 #define MONDAY 1 #define TUESDAY 2 #define WEDNESDAY 3 #define THURSDAY 4 #define FRIDAY 5 #define SATURDAY 6 #define JAN 1 #define FEB 2 #define MAR 3 #define APRIL 4 #define MAY 5 #define JUNE 6 #define JULY 7 #define AUG 8 #define SEPT 9 #define OCT 10 #define NOV 11 #define DEC 12 /******************************************************************* * * GetValidInt(MIN,MAX) reads an integer from the user between given * minimum and maximum values, reprompting the user until she enters * a valid one. If the user types something other than an integer, bad * things may happen. * * INPUTS: min and max, the minimum and maximum (inclusive) values for * the entered integer. * OUTPUT: an integer between min and max, inclusively. * *******************************************************************/ int GetValidInt(int min, int max); /****************************************************** * * GetYear(min,max) reads and returns an integer representing a year between * min and max. * * INPUTS: two integers representing the min and max for the year * OUTPUT: an integer for the year (e.g., 1969) * ******************************************************/ int GetYear (int min, int max); /****************************************************** * * GetMonth( ) reads and returns an integer representing a month of a * year (e.g., between MIN_MONTH and MAX_MONTH) * * INPUTS: none * OUTPUT: an integer representing a month (e.g., 3) * ******************************************************/ int GetMonth (void); /****************************************************** * * GetDay(month,year) reads and returns an integer representing day in * the given month and year, making sure that it is, in fact, a valid * day for that month and year. It assumes that the month and year are * valid. * * INPUTS: integers representing a valid month and year * OUTPUTS: an integer for a (possible) day in that month and year * ******************************************************/ int GetDay (int month, int year); /****************************************************** * * PrintDate(D,M,Y) Prints a date in the common American format * including the "day of week" name, e.g., PrintDate(4,8,1949) prints * "Thursday August 4, 1949". * * INPUTS: integers representing a valid day, month and year * OUTPUTS: none * SIDE EFFECTS: prints to stdout * ******************************************************/ void PrintDate (int day, int month, int year); /****************************************************** * * PrintInterval(d1,m1,y1,d2,m2,y2) prints the number of days between * the two given dates, e.g., PrintInterval(1,1,2005, 1,2,2005) * prints "There are 31 days between Saturday January 1, 2005 and * Tuesday February 1, 2005.". * NOTE: Design changed 2/27/2005, twf, see ECN1 * * INPUTS: six integers representing two dates * OUTPUT: none * SIDE EFFECTS: prints on stdout, reads another date from the user * CALLS: DaysBetween * ******************************************************/ void PrintInterval (int day, int month, int year); /****************************************************** * * PrintMonthName takes an integer representing a month and * prints the standard name for the month w/o any spaces or * newlines, e.g., PrintMonthName(0) prints 'January'. * * INPUTS: an integer representing a valid month * OUTPUT: none * SIDE EFFECTS: prints to stdout * ******************************************************/ void PrintMonthName(int month); /****************************************************** * * PrintDayName takes an integer representing a day of the * week and prints it's standard English name w/o any spaces * or newlines, e.g. PrintDayName(1) => prints 'Monday' * * INPUTS: an integer representing a valid day of week * (MIN_DAY_OF_WEEK to MAX_DAY_OF_WEEK) * OUTPUT: none * SIDE EFFECTS: prints to stdout * ******************************************************/ void PrintDayName(int day); /****************************************************** * * PrintMonth(month,year) prints a minimal calendar block for * the given month. * * INPUTS: integers representing a valid month and year * OUTPUT: none * SIDE EFFECT: prints to stdout * ******************************************************/ void PrintMonth (int month, int year); /****************************************************** * * PrintYear(year) prints a minimal calendar for each month in the * given year. * * INPUTS: an integer representing a valid year * OUTPUT: none * SIDE EFFECTS: prints to stdout * CALLS: PrintMonth * ******************************************************/ void PrintYear (int year); /****************************************************** * * DaysBetween(D1,M1,Y1,D2,M2,Y2) returns the number of days * between M1/D1/Y1 and M2/D2/Y2. For example, * DaysBetween(1,23,2005,1,2,2005) => 10. It does not assume * that the first date is before the second. * * INPUTS: six integers representing two valid dates * OUTPUT: an integer representing the number of days * between the two dates * ******************************************************/ int DaysBetween (int day1, int month1, int year1, int day2, int month2, int year2); /****************************************************** * * DaysInMonth(MONTH,YEAR) returns the number of days in * MONTH of YEAR, e.g., DaysInMonth(2,2005) => 28 * * INPUTS: integers representing a valid month and year * OUTPUT: an integer representing the number of days in that month * ******************************************************/ int DaysInMonth (int month, int year); /****************************************************** * * DaysInYear(YEAR) returns the number of days in * YEAR -- 365 if a normal year and 366 if a leap year. * * INPUTS: integer represeting a valid year * OUTPUT: an integer representing the number of days in that year * ******************************************************/ int DaysInYear (int year); /****************************************************** * * DayOfWeek(D,M,Y) returns an integer representing the day of the * week of the date M/D/Y with 0=Sunday and 6=Saturday. E.g., * DayOfWeek(1,1,2005) => 6. * * INPUTS: three integers representing a valid day, month and year * OUTPUT: an integer representing the day of the week * ******************************************************/ int DayOfWeek(int day, int month, int year); /******************************************************************* * * IsLeapYear takes an integer representing a year and returns 1 (TRUE) if it * is a leap year and 0 (FALSE) otherwise. A year is a leap year if it is * evenly divisible by 4 and not by 100 unless it is also evenly * divisible by 400. * * INPUTS: an integer representing a year between MIN_YEAR and MAX_YEAR * OUTPUT: 1 (TRUE) or o (FALSE) * *******************************************************************/ int IsLeapYear (int year); /***************************************************** * * DayNumber(int day, int month, int year) returns the * number of the given date in the year, e.g., * DayNumber(2,2,2005) => 33. This is loosely related to * the concept of a julian date. * * INPUTS: three integers representing a valid day, month and year. * OUTPUT: an integer between 1 and 355/365 representing the day * number of the day (depending on whether or not the year * is a leap year. * ******************************************************/ int DayNumber(int day, int month, int year); /****************************************************** * * DaysSinceAnchor(day, month, year) returns the number of days since * anchor (e.g., ANCHOR_DAY, ANCHOR_MONTH, ANCHOR_YEAR). We assume * that the given date is *after* the anchor date. * * INPUTS: three inters for a dalid day, month and year * OUTPUT: an integers equal to the number of days since * the anchor date * ******************************************************/ int DaysSinceAnchor (int day, int month, int year);


CSEE | 201 | 201 S'05 | lectures | news | resources | help |

Sunday, 27-Feb-2005 17:01:08 EST