

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Due: On the date shown on the LMS assignment drop box Remember that homework problems are to be done by you alone! We will check your scripts for copying using a system called MOSS. Introduction You are to write a C++ program that reads a list of months from a file and puts a calendar for each month into a separate file. Sample output is shown below. The output is to be put into a file with the name of the month followed by the string”.txt”. For example, if the month is “January” then the output file will be “January.txt” and if it is “May” it will be “May.txt”. The input file will consist of a list of month names with each name followed by white space. Each name will have one upper case character followed by the rest all in lower case. The names will be stored in a file called “input.txt”. Discussion I suggest that you organize your program into at least the following set of functions: daysInMonth – given a month (number from 1 to 12), return that number of days in that month in 2009. dayOfWeek – given the day and month return what day of the week that date falls on in
monthNumber – given the name of a month (1 = January, 2 = February, …, 12 = December), return its number. displayMonth – given the name of the month, and the day of the week that that month begins on (a number between 0 and 6, where 0 = Sunday, 1 = Monday, …, 6 = Saturday), put a the calendar for that month into a file. fileName- given a month create a file name for that month as “month.txt”. Hint: The “+” function joins two strings. main – loop to repeatedly read months from a file and then call the other functions to create a calendar for that month and put it in a file. Most of these functions should be fairly straightforward to write. Perhaps the most difficult thing is displaying the first week of each month since most months don’t start on a Sunday and require some blank space at the beginning of the line before the 1. You will be doing this in function displayMonth and one of the parameters to function displayMonth is the day of the
week that the month begins on. If a month begins on day 5, say, which is Friday, then you must display a string of three blanks under Sunday, Monday, Tuesday, Wednesday and Thursday before displaying the 1. This is easily done with a for loop. The other thing that might be difficult is deciding when to start a new line in the display of a calendar. The easiest thing to do for this is count how many dates are displayed on the current line. When this count is incremented to 8, start a new line and reset the count to 1. Make sure that you initialize the count correctly for the first line in a month to include the blank spaces at the beginning of the line. You might find switch statements useful in one or two of the functions, for example, the function to compute the number of days in each month. For easy debugging you may want to start by writing your program to write a calendar for January with the output going to the screen, then add the other months, and then add the code to read the months from a file and put the results into a file. Sample Output 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 What to Turn In. Your TA will grade your program by running it on several examples. Thus, make sure that your program works for more than just the sample output above. Your program should be formatted nicely and it should be well commented. Identifiers should be chosen to reflect how they are used. You must submit the text of your program as a .cpp file using the LMS system. If you are using Visual C++ then you will find the .cpp text inside the directory that Microsoft makes for each project (look at the .cpp file using Wordpad or Notepad to make sure you got the right one). Save your program until you get the grade back in case your TA has any problems grading your submission. Grading: Prints a calendar for January 2009 30 points Prints a calendar for any month in 2009 20 points Reads month names from a file 10 points Checks for valid input file with valid names 10 points Outputs data to a file with the name of the month + “.txt” 10 points Program is well commented and easy for TA to read 10 points Program output is easy to read and understand 10 points