ࡱ> bda'` 0"bjbj{P{P Z::D4    ^ ^ ^ r :::8rD,r /lL(///////$0hU3"&/^ "&/  ;/ 8^ //,F ^ - q:-".Q/0/-"w4w4D--w4^ -=Q_ kS===&/&/v===/r r r $ r r r r r r        Project 1 (20 points) Assigned: Thursday, January 14, 2010 Due: Thursday 21, 2010, 11:59 PM Programming Assignment #1 Display a 12-month Calendar Abstract Write a C program that displays a twelve month calendar for an arbitrary year. Prompt the user for the year of the calendar, and print out the calendar month by month, so that it looks like a real calendar. Outcomes After successfully completing this assignment, you should be able to: Develop a C program on a Unix platform Design a program that contains nested selection and iteration constructs Specify the loop invariants that you use to reason about your program Use advanced formatting strings and conversion specifiers to do I/O in a C program Before Starting Re-read Chapters 1 and 2 of K&R or Chapter 2 of D&D. Read 3.1-3.5 K&R or Chapters 3 and 4 of D&D. This assignment bears a slight resemblance to exercise 4.35 of D&D and to programming assignments in recent terms of CS-2301. The Assignment Write a C program that displays twelve-month calendar for a particular year. The program should prompt the user for the year to be printed, and then it should figure out (a) whether the year is a leap-year and (b) what day of the week the chosen year starts on. The calendar should be formatted as shown in the sample execution below. Note that numbers the days must be right-justified under the names of the days and that two spaces separate the names of the days from each other. Interfaces The interface provides the functions printf and scanf. Assumptions and Restrictions The user may enter any non-negative integer for the year. You must calculate the calendar according to the modern international standard calendar that was introduced by Pope Gregory XIII in the year 1582. For input years earlier than 1582, calculate them as if the modern calendar were in effect. In the modern calendar, years that are divisible by 4 are leap years, except that years divisible by 100 are not leap years unless they are also divisible by 400. That is, there are 97 leap years every four centuries. You will have to figure out what day of the week the calendar starts on. You may do this by referring to a known year in which you know the day of the week of a particular date. You will then work backwards from that known date to find the start of the input year. Sample Execution MONTHLY CALENDAR Please enter year for this calendar:- 2009 *** CALENDAR for 2009 *** January 2009 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 31 February 2009 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 . . . (output continues for all 12 months) Implementation Notes Since we have not yet studied arrays, strings, or arrays of strings, you should design your algorithm to use if-else or switch statements to print the month names and to set other variables. You must partition your program into multiple functions. Here is an example partition: The function main() prompts the user for input, calls a function of your own design to determine the starting day of the input year. It then invokes the function printCalendar() to actually print the twelve month calendar. The function printCalendar() takes two arguments, the year number and the starting day. It then loops through the year and calls the function printMonth() twelve times, once for each month. The function printMonth() takes two arguments, the year number and the starting day of that particular month, and it returns the number of the day on which the next month starts. Print month has to first call a function printMonthName() and then print out the days of the month in calendar format. The function printMonthName() takes the year number and the month number as arguments, prints out the line identifying the month, and returns the number of days in that month. The example output of printMonthName() should look resemble the following: January 2009 Since we are not using arrays of strings, printMonthName() should use a switch statement to select and print the name of the month and to determine the number of days in that month. If the month is February, it should also figure out whether the year is a leap year and return the correct number of days. Algorithm and Loop Invariants There are many sources on the web and at WPI for a suitable algorithm for this assignment. You may consult any of these, but you must cite your source. If you worked out the algorithm on your own, you should say in your write up file that this is entirely your work. If you borrowed some or all of an algorithm from someone else or from somewhere else, do not copy it. Write it out in your own words and your own coding style. Also, please explain enough about how the algorithm works that the graders can conclude that you understand it. This project requires at least two loops. For each loop, write a loop invariant that is, a logical statement in English or mathematical notation that says what salient facts are true about the relationships of the variable at the same point in the loop for each iteration. Deliverables Write a document called README.txt or README.doc summarizing your program, how to run it, and detailing any problems that you had. Also, if you borrowed all or part of the algorithm for this assignment, be sure to cite your sources and explain in detail how it works. Be sure also to specify the loop invariant of each loop. From your CCC Linux shell, submit your C source code file using the following turnin command: /cs/bin/turnin submit cs2303 PA1 README Programs submitted after 11:59pm on due date (January 21) will be tagged as late, and will be subject to the HYPERLINK "../../index.htm" \l "_Late_policy"late homework policy. Grading This assignment is worth twenty (20) points. Your program must compile without errors in order to receive any credit. It is suggested that before your submit your program, compile it again on a CCC system to be sure that it does not blow up or contain surprising warnings. Correct compilation without warnings 2 points Correct execution with graders test cases 2 points Correct usage of scanf() to get inputs from user 1 point Correct usage of print() to print the various lines of the calendar 3 points Correct usage of conditional and loop statements 5 points Satisfactory README file 2 points Loop invariant for each loop in README document 5 points     Programming Assignment #1  PAGE 1 January 21, 2010 CS-2303, System Programming Concepts, C-term 2010    !)+57;AIJLNR\]^vwxz  > @ A g h m n o 2 x | ƿƻƷh h.6h+h hh. h ~dh ~d hXNHhdOh h ~d6h ~dhg h `h ` h `h.hgmHnHuhImHnHujh `UmHnHu hTh4hw(hXh44]o y 2 x edCc+gdledCc+edCc+gd=edCc+gdedCc+gdedCc+gdedCc+edCc+gddOedCc+gd ~dedCc+gdg"$ !k&#$-D/M a$edCc+gdw("^""|     ! Q k    4 > X Y ^ m   / ? L k FM37BCɷɰзаܬܬЬhg h!h.#h!h.5CJOJQJ^JaJ h!hD9hlh=h+hXhxOhdOhh h.6hu1h.h C C&7`a%Gi ( Px 4 #\'*.25@9edCc+gdmAedCc+gdledCc+edCc+edCc+gdgedCc+gdledCc+}~&amn~`4.=BCjkx)6侬侬ྛhc5CJOJQJ^JaJ hmAhc hcNHh#hchc5CJOJQJ^JaJhch #hWLhWL5CJOJQJ^JaJh=hWLhmAh[yh. hlNHhlhg hgNH6':`u4k)SO]edCc+gdzpedCc+gd ( Px 4 #\'*.25@9^edCc+gdmAedCc+gdmAedCc+gdWLedCc+edCc+gd!edCc+6;@BRS`p)?LNNlm%B ھȷڷȷڳگڥw#hV =hV =5CJOJQJ^JaJhV =h. hzphzp hzpNH hzp6]hzp h05 NHh05 h hmAhmA hmANHhc#hmAhmA5CJOJQJ^JaJhmAhmA5CJOJQJ^JaJ#hchmA5CJOJQJ^JaJ),u} /!~!!!""""" """edCc+edCc+gd4edCc+gdw(edCc+gdedCc+gdedCc+gdedCc+gdedCc+edCc+gdzp   i+,6:?@ESTzĻ˴rcrhX5CJOJQJ^JaJ#h!h.5CJOJQJ^JaJ hV =NH#hV =h.5CJOJQJ^JaJh h.6hhIh h. h4h4h46NH] h46]h4 hzp6]#h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(1톡v'YC2[S{/dҸ-s!޼aZB:Jyi$5M*^zϱ|63+>_ET=6CG|pz)Lޟ_#]]Dލz Vf^ND67'L(7ST84ݏfc`: k#mAes>ِb_؁O91oIt ,hG w^U,NruRG.fw`@X+̥t߼M+a}ƪύ̭.̭̍|hj{E-:-y]*r|;ϭPO~欸sxH Ο|Xp\0e{@r7m9j\VPPZz^:4rv$F"SْݪU]^S`(ӓ"{Sp³(9! OP( )7)^q:8 o>$]\>/m+N'M98(頩V<)hGa=п*#~g!3>5LQ8EBM޷ޫÇ uua3n4xi7AKJX!V9z31P[.]azO7N!^!?I 'BuIENDB`DyK  yK 8../../index.htmyX;H,]ą'c _Late_policy H@H ~dNormal CJOJQJ_HaJmH sH tH N@"N Heading 2dd@&[$\$5CJ$\aJ$J@rJ V = Heading 3$x@&5CJ\aJB@rB dO Heading 4$xx@&5\DA@D Default Paragraph FontRiR  Table Normal4 l4a (k(No Liste@ HTML Preformatted7 2( Px 4 #\'*.25@9CJOJQJ^JaJB^@B Normal (Web)dd[$\$4U@4 Hyperlink >*phDV@!D FollowedHyperlink >*phN>@BN  ~dTitle$<@&a$5CJ KH\^JaJ >J@r>  ~dSubtitle$@&a$^JTO1BT `Style Title + Garamond CJOJQJ>6@b>  List Bullet 2  & F6B@r6 ! Body Text xx0Oq0 xO Body Text24Oq4 !Indented ^4@4 !Header  !4 @4 !Footer  !.)@. ! Page NumberNON 4 Char Char3 CJOJQJ_HaJmH sH tH B0@B [y List Bullet & F<<FD@F mA List Continueh<<^h336@]oy2xC& 7 ` a  % G i   ' : ` u 4 k )SO],u}/~ "#%&\]^0Cc+0Cc+(0]Cc+0Cc+(0]Cc+0oCc+ 0oCc+ 0oCc+ 0oCc+ 0oCc+(0]Cc+0Cc+(0]Cc+0Cc+0Cc+80Cc+0Cc+80Cc+0Cc+0Cc+0Cc+(0]Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0& Cc+0&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OJQJo(PP^P`CJOJQJo(^`.^`.pp^p`.@ @ ^@ `.^`.^`.^`.^`.PP^P`.-C!>#\n_2i~}|Cc+6517 05 48=q4V7$w(u1.3ri7V =HHJx5MdO1UUW ` %a ~dzpes[ymA.Ig1WL/ls[qD9OcAlD!la6+X xO==@4@@UnknownGz Times New Roman5Symbol3& z Arial?5 z Courier New9Garamond;Wingdings"1h[&lf2&Y5 /5 /9#4d  8QHX.32-Programming Assignment #1 - 12-month Calendar5CS-2303 -- System Programming Concepts (C-term, 2010) Hugh C. Lauer Hugh C. LauerD         Oh+'00<H\ t    0Programming Assignment #1 - 12-month Calendar8CS-2303 -- System Programming Concepts (C-term, 2010)Hugh C. Lauer Normal.dotHugh C. Lauer8Microsoft Office Word@Vn @^[@hߒ@Rg5՜.+,D՜.+,t0 hp   Worcester Polytechnic Institute/  ' .Programming Assignment #1 - 12-month Calendar Title 8@ _PID_HLINKSApF../../index.htm _Late_policy  !"#$%&'()*+,-/012345789:;<=>?@ABCDEFGHIJKLMNOPRSTUVWXZ[\]^_`cRoot Entry F`reData .1Table64WordDocumentZSummaryInformation(QDocumentSummaryInformation8YCompObjq  FMicrosoft Office Word Document MSWordDocWord.Document.89q