This assignment is Due on: Day: Wednesday, April 8, 1998 Time: Before 6:00 PM WARNINGS: TURN IN THIS ASSIGNMENT ELECTRONICALLY USING "turnin". LATE ASSIGNMENTS WILL NOT BE ACCEPTED. ---------------------------------------------------------------------- The purpose of this homework is to reinforce explanation of the following C programming concepts: Format and structure of a C program Function and variable declarations Compiler-initialized variables Declaration, storage, and access methods for arrays Generating output Macros #include, #define, and #ifdef directives In addition, the following utilities will be discussed and used: lint A C syntax checker cc The C compiler make A configuration management program indent A C source code beautifier To complete this homework, you will need the files "Makefile", and "mycal.c", which should have been included with your getjob distribution. -----------------------Start Answer Here----------------------- [p0] 5.0 points Check the syntax of your program by typing "lint mycal.c". Explain what "lint" is doing, and what is meant by any output messages that it produces. Modify "mycal.c" so that when you "lint" it again, no output is produced. What did you have to change? ------------------------End Answer Here------------------------ -----------------------Start Answer Here----------------------- [p1] 4.0 points Create the "mycal" executable by typing "make". Explain what "make" is doing. Once "make" is done, run the program by typing "mycal". Explain what happens, and why. ------------------------End Answer Here------------------------ -----------------------Start Answer Here----------------------- [p2] 5.0 points Remove the "mycal" executable by typing "make clean". Recreate the "mycal" executable by typing "make debug" . Run the program by typing "mycal" and explain what happens and why. ------------------------End Answer Here------------------------ -----------------------Start Answer Here----------------------- [p3] 4.0 points Explain in some detail what each of the macros YEAR, MONTH, WEEK_DAY, and MONTH_DAY is, and what it is used for. ------------------------End Answer Here------------------------ -----------------------Start Answer Here----------------------- [p4] 8.0 points Read the on-line manual page for the mktime(3c) library function. Now try running "mycal" with the following dates as input: (a) 1 16 1998 (b) 2 29 2000 (c) 12 31 1969 (d) 1 20 2038 Explain what happens in each case, and why the program produces the output that it does. ------------------------End Answer Here------------------------ For this next part, you will need to know whether the current year is a leap year. Here are the rules for determining leap years: 1. For years up to and including 1752, a leap year is any year that is evenly divisible by 4. 2. For years after 1752, a leap year is any year that satisfies the following conditions: a. Evenly divisible by 400, or b. Evenly divisible by 4, and NOT evenly divisible by 100 -----------------------Start Answer Here----------------------- [p5] 3.0 points Explain the concept of "short-circuit evaluation" of conditional expressions in C, and how this feature of the language might be used in efficiently determining whether a particular year was a leap year or not. ------------------------End Answer Here------------------------ Write a macro called IS_LY that takes a single parameter (assumed to be an integer expression whose value represents the year to be checked) and evaluates a conditional expression to determine if that year is a leap year or not. Use "short circuit evaluation" to make the IS_LY macro as efficient as possible (i.e. no unnecessary evaluations, calculations, or comparisons). Two things to think about: 1. MAKE SURE you understand all the nuances of the above leap year "rules" before writing your macro. 2. Direct comparison to 0 is NEVER "unnecessary". -----------------------Start Answer Here----------------------- [p6] 6.0 points Include the source code for your IS_LY macro here. ------------------------End Answer Here------------------------ Go ahead and use the IS_LY test in your program, so as to correct any anomalous output that you observed in [p4] above. Now consider this: Given the range of dates for which the mktime(3c) function is "valid", it seems pointless to take into account all the leap year "rules" that we allowed for in the IS_LY macro, because the "evenly divisible by four" rule suffices for all leap years in the range of years that mktime(3c) "understands". -----------------------Start Answer Here----------------------- [p7] 4.0 points Explain why it is better that our IS_LY macro calculates the "right answer" under ALL possible input circumstances, rather than just the range of ones for which mktime(3c) currently "works" (think carefully about your answer to this problem - failure to completely understand the ramifications of this one simple issue is the root cause of the Year 2000 problem). ------------------------End Answer Here------------------------ Now modify the main() function in "mycal.c" so that it prints a representation of the entire month's calendar for the selected date, with that date "highlighted" by being enclosed in [ ]. For example, if the selected date were April 8, 1998, then your program output would look like this: Today is Wednesday, Apr 8, 1998 Sun Mon Tue Wed Thu Fri Sat 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 Note that this output is what would be produced from a program with the DEBUG macro undefined. -----------------------Start Answer Here----------------------- [p8] 8.0 points Insert the source code for your revised main() function here. ------------------------End Answer Here------------------------ -----------------------Start Answer Here----------------------- [p9] 3.0 points "Beautify" your source file by typing "make pretty" (this will invoke a program called "indent" - note that you will be asked for confirmation before any files are modified). Examine your "beautified" source file, and compare it to the original version (which can be found in "mycal.c.BAK, if you are using one of the acmes). Describe what "indent" did to your program. Explain why "indent" might be useful. ------------------------End Answer Here------------------------