Details of this Paper

Assignment 8

Description

solution


Question

Assignment 8;Write a program that prints a calendar for one year, given the day fo the week that January 1 falls on. Your solution should include a printMonth function that prints any month given the day of the week on which a month starts and the number of days in the month. Each successive month starts on the day of the week that follows the last day of the preceding month. Days of the week will be numbered 0 through 6 for Sunday through Saturday.;Extra Credit Opportunity: If you are not interested in the extra credit, you may email me at any time and I will provide you with the two functions that form the core of the program and are the most difficult to get right. If you complete the assignment without asking for these, you will get the extra credit. I realize that it would not be hard to cheat on this and get the code from a friend. Please don't.;Do not use classes, arrays, or structs in this project!!;Your output should look exactly like the one in this sample screen output;What year do you want a calendar for? 2002 What day of the week does January 1 fall on (0 for Sunday, 1 for Monday, etc.)? 2 2002 January S M T W T F S --------------------- 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 S M T W T F S --------------------- 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.... December S M T W T F S --------------------- 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;Additional Requirements and Hints;Your program must determine whether a year is a leap year exactly, not just by checking for divisibility by 4 as the problem indicates. Also remember that you are free to steal the isLeapYear function from the lessons.;It is extremely important that you use stepwise refinement when designing this program.;Required! You MUST have a single function named "printMonth" that prints out ANY month, based on its parameters. In other words, don't create 12 separate functions, one named "printJanuary", one named "printFebruary," and so on. In addition, you must have only ONE call to this printMonth function, in a loop that calls the function 12 times.;Let me describe my solution to this problem, not so that you can try to match it exactly, but so that you'll know if you are going way off into the wrong direction. I had 8 functions all together including main. 4 of them were 5 lines or less. 2 of them were fairly long functions but only because they were switch statements with 12 branches -- hard if not impossible to decompose further. That leaves 2 functions which were 8 - 10 lines long. One of these was the printMonth function.;When I count lines I count only the body of the function and I don't count declaration statements or blank lines or comments, but I do count a line if it has only a } on it.;Make sure each of your functions performs a single logical task (not two). If you find yourself trying to name a function with the word AND, it probably means the function should be divided into two.;More hints on the printMonth function: Don't try to split up the printMonth function into weeks. Instead, use a for loop that goes from 1 to the number of days in the month. Use the setw(3) function to line up your dates. Inside the for loop have an if statement with a cout << endl, inside to force a new line when the day is saturday. The hardest part of this program is getting printMonth to set it up so that next time it is called your variable which tells printMonth what day of the week to start on is set correctly.;Printing out the month names: They don't need to be centered. Each month name should start right above the letter "T", as illustrated in the sample output.;Don't forget that 20 percent of your score on this assignment will be based on comments.;It will be very important to use iterative development on this project. For example, you might first write the program assuming that every month has 31 days and starts on the same day. Just write out the numbers 1 to 31 all on the same line for now. After you have that much working well, then you can work on getting your program to print newlines at the right times so that there are 7 days in a week, figure out how many days are in each month, get each month to start on the right day, and so on. Just take it one step at a time, and make sure things work correctly at each step.

 

Paper#65042 | Written in 18-Jul-2015

Price : $70
SiteLock