//========================================================================= #define PROGRAMMER "SOLUTIONS, NoFrills" #define PROG_CODE "soln" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "HW #2B" #define REVISION (0) #define TITLE "Beyond Numeracy" #define SUBTITLE "Programming Exercise #4.6" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "02b0soln.txt" //========================================================================= // PROBLEM: // // Rewrite tha Calendar Program of Section 4.6 so that the User only input // a year. // // To permit printing the calendar on a single 8.5x11 sheet of paper, // print two months side by side. // // The resulting calandar should be printed to the file calendar.dat. // // SOLUTION APROACH // // The problem doesn't state whether the months are to be printed in // columns or rows, hence it is our choice to print them as: // // JAN FEB JAN JUL // MAR APR FEB AUG // MAY JUN or MAR SEP // JUL AUG APR OCT // SEP OCT MAY NOV // NOV DEC JUN DEC // // The existing program prints a calandar as single column of months. // If we use the second option above, it means that what we really // need is for the same program to print only half a year - in the exact // same fashion that it currently does! All we have to do is, on every // line that is printed, print an equivalent line (on the same line) // for a second half calendar. // // NOTE: The following is not pseudocode for the actual algorithm but // instead for an "algorithm" that solves the more problem of how to // get a program that does what we want it to do. Keep in mind that // the purpose of pseudocode is to establish a clear plan for solving // the problem at hend. In this case, since we have a starting point // with a prior program, it is reasonable to describe, in adequate // detail, the steps that need to be accomplished to modify the program // to meet the new needs. // // The steps to be followed are as follows: // // TASK #1: Implement the program as it presently exists in Sec 4.6. // The code is available on the course website in the // text book section. // TASK #2: Modify it to require only a year from the yser. // Using the formula given in the problem, compute the // day_code for Jan 1st and whether it is a leap year. // TASK #3: Modify it to print a second image shifted right. // This should be a simple matter of dublicating some printf() // statements. // TASK #4: Modify it to use a constant number of lines per month. // Just need to print a line of blank dates if necessary. // TASK #5: Modify it to prints only six months in a column. // Trivial (should be, anyway). // TASK #6: Identify which variables must be split between columns. // Probably daycode, month, and day - perhaps others. // TASK #7: Modify it to print the complete calendar. // Should just be a matter of using the new variables. // TASK #8: Modify it to print to a file instead of the screen. // Open and check the file and convert all of the printf() // statements to fprintf() statements using a search and // replace - or perhaps a macro. // TASK #9: OPTIONAL - pretty up the printout, perhaps to: /* |=======================================================================| | 2006 CALENDAR | |=======================================================================| | January | July | | Sun Mon Tue Wed Thu Fri Sat | Sun Mon Tue Wed Thu Fri Sat | | 1 2 3 4 5 6 7 | 1 | | 8 9 10 11 12 13 14 | 2 3 4 5 6 7 8 | | 15 16 17 18 19 20 21 | 9 10 11 12 13 14 15 | | 22 23 24 25 26 27 28 | 16 17 18 19 20 21 22 | | 29 30 31 | 23 24 25 26 27 28 29 | | | 30 31 | |=======================================================================| | February | August | | Sun Mon Tue Wed Thu Fri Sat | Sun Mon Tue Wed Thu Fri Sat | */ // A look at the calendar reveals the fact that the month of July // starts on the same day of the week as the month of January in leap // years and the day prior in non-leap years. That should make things // a bit easier.