UMBC CS 201,Fall 03
UMBC CMSC 201 Fall '03 CSEE | 201 | 201 F'03 | lectures | news | help

CMSC 201
Programming Project One

Dates

Out: Wednesday 9/24/03
Due: Before Midnight, Tuesday 9/30/03

The Objective

The objective of this assignment is to get you started writing programs in C in the UNIX environment. Its main emphasis is design, so we will be designing the project together in class. This project will also give you practice writing functions, loops, switch statements and using separate compilation.

The Background

You are just beginning to learn to program in C and you want to challenge yourself by writing a large enough program to test your design skills and to give you practice with separate compilation. You decide to write a program that you can release as public domain software (give away to others). It should be something that is a little bit useful and maybe even a little bit fun ... something to do with dates.

First let's think about the useful part. It would be useful to be able to find the Julian date of any date the user enters. The Julian date is what day of the year it is. e.g. 01/01 corresponds to the julian date 1, 01/25 corresponds to the julian date 25, and 02/01 corresponds to the julian date 32.

Now the fun part ... It would be fun (and maybe even useful) for the user to be able to enter the current date and someone's birthdate and let the program respond with their age. e.g. I was born 9/29/1949, so today 9/25/2003, I am 53 years old. Beginning on Monday, 9/29/2003, I will be 54, until this time next year ... but you know how ages work.

And now the totally useless, but fun part ... It would be fun for the program to tell what a person's astrological sign is, given the person's birthdate. Here is a chart of dates and signs:

Astrological Sign Beginning Date Ending date
AriesMar 21Apr 19
TaurusApr 20May 20
GeminiMay 21June 21
CancerJune 22July 22
LeoJuly 23Aug 22
VirgoAug 23Sept 22
LibraSept 23Oct 23
ScorpioOct 24Nov 21
SagittariusNov 22Dec 21
CapricornDec 22Jan 19
AquariusJan 20Feb 18
PiscesFeb 19Mar 20

The Task

Design (to be done in class) and code a project that after printing a greeting to the user, presents the user with a menu and allows him to choose to find a julian date, find someone's age or find someone's sign given their birthday. After displaying the results, the user should be presented with the menu again, so that s/he can continue to make choices.

Since you are distributing this software to others, you must use separate compilation and provide the interface for the user. This is in the form of a well commented header (.h) file. You must have 3 files. The file that contains main() MUST be called proj1.c; the file containing the function definitions MUST be called dates.c and the header file MUST be called dates.h

You are required to use a switch statement to handle the menu requests. There are also other places where the switch statement is the appropriate choice too.

You must adhere to the design given in class. The function prototypes given below must be used and may NOT be altered in anyway.

int FindDaysInMonth (int month, int year); int FindJulianDate (int month, int day, int year); void DisplayMenu (void); int IsLeapYear (int year); int FindAge (int currentMonth, int currentDay, int currentYear, int birthMonth, int birthDay, int birthYear); void PrintGreeting (void); void PrintSign (int month, int day); int GetValidDay (int min, int max); int GetValidYear (int min, int max); int GetValidMonth (int min, int max); The following symbolic constants should be used and they should be placed in your proj1.c file above main(): #define MIN 1 #define MAX 12 #define MINYEAR 1000 #define MAXYEAR 9999 #define JULIAN 1 #define AGE 2 #define SIGN 3 #define QUIT 4

You must handle leap years properly and according to the following rule:

  • A year is a leap year if the 4-digit year is evenly divisible by 4 but not also evenly divisible by 100, however a year is also a leap year if it is evenly divisible by 400.

    Sample Run

    linux1[101] % a.out This program allows you to have fun with dates You can find the Julian date from the month day and year, or you can find out someone's age or their astrological sign. 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 1 Please enter the number of the month : 3 Please enter the 4-digit year : 2003 Please enter the day : 1 The Julian date for 3/1/2003 is 60 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 1 Please enter the number of the month : 3 Please enter the 4-digit year : 2000 Please enter the day : 1 The Julian date for 3/1/2000 is 61 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 1 Please enter the number of the month : 3 Please enter the 4-digit year : 2004 Please enter the day : 1 The Julian date for 3/1/2004 is 61 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 2 Current month : Please enter the number of the month : 9 Current year Please enter the 4-digit year : 2003 Current day Please enter the day : 25 Birth month Please enter the number of the month : 9 Birth year Please enter the 4-digit year : 1949 Birth day Please enter the day : 29 Your age is 53 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 2 Current month : Please enter the number of the month : 9 Current year Please enter the 4-digit year : 2003 Current day Please enter the day : 29 Birth month Please enter the number of the month : 9 Birth year Please enter the 4-digit year : 1949 Birth day Please enter the day : 29 Your age is 54 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 3 Please enter the number of the month : 8 Please enter the 4-digit year : 1980 Please enter the day : 23 The sign for 8/23 is Virgo 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 3 Please enter the number of the month : 8 Please enter the 4-digit year : 1940 Please enter the day : 2 The sign for 8/2 is Leo 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 5 Sorry 5 is not a valid response 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 3 Please enter the number of the month : 14 Sorry, the month should be between 1 and 12 Please enter the number of the month : -1 Sorry, the month should be between 1 and 12 Please enter the number of the month : 4 Please enter the 4-digit year : 03 Sorry, the year should be between 1000 and 9999 Please enter the 4-digit year : 1911 Please enter the day : 36 Sorry, the day must be between 1 and 30 Please enter the day : 17 The sign for 4/17 is Aries 1 - What's the Julian Date 2 - What's My Age 3 - What's My Sign 4 - Quit Enter choice : 4 linux1[102] % exit

    Although your output need not be identical to the above, all information (including the greeting) must be present.

    Please be aware that this is definitely NOT a complete test of the program. Your testing should be much more extensive.

    Submitting the Program

    You are to use separate compilation for this project, so you will be submitting three files.
    Your C source code file that contains main() MUST be called proj1.c. The file which contains the function definitions MUST be called dates.c and the header file MUST be called dates.h

    To submit your project, type the following at the Unix prompt. Note that the project name starts with uppercase 'P'.

    submit cs201 Proj1 proj1.c dates.c dates.h

    To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.

    submitls cs201 Proj1


    CSEE | 201 | 201 F'03 | lectures | news | help

    Wednesday, 24-Sep-2003 12:00:10 EDT