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.
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 maRcHy 2013
$ cal -m 3 2014
$ cal -m MArCh
$ 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.
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.”
Submit your files cal.c
and cal.txt
via Moodle after you are finished. 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.
If you are not clear as to what your program should produce (i.e., the project description did not provide enough clarification for you), you should talk to me during lectures and labs. I will also give details instructions on what your program should produce and how to approach the problem during lectures. So, it goes without saying that attendance is important.
You can download San's 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
If your program works for cases specified in the first 10 examples, you will recieve 90% for project 1. For each example working correctly, you will recieve 9% of the total score for project 1. Your code's readability, style (your code should follow closely to the style guide), and documentations are worth 10% of project 1.