Calendar
Overview
The de facto international standard civil calendar is the Gregorian calendar. Pope Gregory XIII introduced it in October 1582 to fix some problem that the Julian calendar was having. Every unix system has a command called cal
for printing the Gregorian calendar. The cal
program on Ubuntu can also print the Julian calendar when requested.
Your job is to write a simplified version of cal
. Your version does not have to print the Julian calendar. It fact, your version should assume that the Gregorian calendar has been in use all along starting in year 1. Your version should perform as documented in this manual page.
Steps
First, you should get to know how the Ubuntu version of cal
works. To do this, try issuing the following commands at your unix command line prompt and carefully note the outputs.
$ cal -m 11 2010
$ cal -m 13 2011
$ cal -m mar 2012
$ cal -m maRc 2013
$ cal -m MARCH 2014
$ cal -m MARCHY 2015
$ cal -m 5
$ cal 18
$ cal 2018
$ cal
Next, design your own cal
algorithm so that it works as specified in the manual page. You should use the outputs from the issued commands above as a guide as to how your program should behave when the manual page does not give enough detail.
Last, translate your algorithm into a C program. Your program should be called cal.c
. You should also modify the given manual page cal.txt
to make it better. For example, your man page should describe all the valid ways to specify a month. It should also document any bugs the program has.
Leap Years
A leap year is a year that has 366 days instead of the usual 365 days. For the Gregorian calendar, each leap year has 29 days in February rather than the usual 28. It defines a leap year to be “a year divisible by 4 but not by 100, or divisible by 400.”
Deliverable
Email your files cal.c
and cal.txt
to . If you want to communicate anything to me then write in up in a (text file) called README
and send it along with your submission.
Notes
- Britain and the British Empire adopted the Gregorian calendar in 1752. Your program must give correct output for all months and years since January 1753. It doesn’t matter what your program prints in response to inputs earlier than that.
You can download my cal program and try it out. The file is a linux ELF-64 binary executable. Once downloaded, make sure that the file has execute permission set. You can do this by typing
chmod a+x ~/Downloads/cal
before trying to run it. (I’m assuming you downloaded the file into your ~/Downloads directory.) Since it is a namesake of the system cal program, you have to use its full name to run. That is, you have to type something like
~/Downloads/cal feb 2020