Question: Writing functions passing parameters Call functions with parameters C++ strings C++ formatted output Multiple For loops String Arrays Integer Arrays Moderately complex algorithms Description: Your
Writing functions passing parameters Call functions with parameters C++ strings C++ formatted output Multiple For loops String Arrays Integer Arrays Moderately complex algorithms
Description: Your main objective is to write a function that prints out a calendar year. Your program will accept a single input value, that of a 4 digit year. Your program will then write the calendar to standard output starting with January and proceeding through December. You will use the routine that you produced in the previous assignment to produce the individual month print.
Programming Specifications:
Upon execution of your program you will prompt the user to input a year equal to or to the year 1582 when the Gregorian calendar was normalized. Your program must make sure that a valid year was entered and values less than 1582 are not allowed. If an invalid year is input you will continue to prompt the user for a year until one is entered.
Your program must recognize when a year is a leap year. A leap year is a year that is divisible by 4 and not 100 unless it is also divisible by 400.
Your program must be able to determine what day of the week the 1st of a month starts on given a year.
.Functions are used and parameters are passed and values returned.
Design Considerations: Approach the project in steps.
Make sure that your PrintMonth routine works properly before you proceed any further. If you need to do any corrections from Assignment 4, make those corrections first.
Write and test the code to read in an integer. Make sure the integer you read in is above 1581 when we started to use the Gregorian Calendar. Continue to ask for a valid number (printing out an error message) until one is entered. I would suggest this as a separate routine that returns the year.
Be sure you can determine if the year that is entered is a leap year or not. Is it divisible by 4 and not 100 or divisible by 4 and divisible by 400.
Given a month ( 1-12) be sure can determine what day of the week (0 through 6) the first starts on for that year.
Write the for loop that calls the PrintMonth routine that prints out the months 1 through 12 sending it information on each one on what day the 1st starts on and whether it is a leap year or not.
You will most likely need the following routines:
// Returns true if the year passed in is a leap year, false otherwise. bool isleapyear (cons int year); // Returns the day of the week the 1st starts on given a year and month. // 0 would mean Sunday, 1 would mean Monday, etc. int DayOfWeek( const int month, const int year); // Prints the year by calling PrintMonth 12 times. // Calls IsLeapYear, DayOfWeek, and PrintMonth. PrintYear(const int year);
Required Algorithms: Use the following algorithm to determine what day of the week a date falls on. Use integer division where the remainder is discarded. Do not round off any values or make any modifications to the algorithm. This is actually called Zeller's Congruence and is a widely accepted method for calculating the day of the week a date starts on. It works fine.You will have to declare some varibles and add of course syntax such as semicolons.
// d, a, y, and m are integers used for interim calculation. You just declare these. // month is the Month (1-12), year is the year, and the day will always be 1.
day=1; a=(14-month)/12 y=year-a m= month+12*a-2 d=(day+y+y/4-y/100 + y/400 + (31*m/12))%7 The value d will be between 0 and 6. 0 is Sunday, 1 is Monday, 2 is Tuesday, 3 is Wednesday, 4 is Thursday, 5 is Friday, 6 is Saturday
Extra Credit: Modify your program to write the calendar out to a file called cal.dat instead of standard output. (10 Points)
Grading Criteria:
(25 Points) The program compiles and executes without exception and produces output. The grading of the output cannot be accomplished unless the program both compiles and executes. If the graders must make changes to your program to allow compiling on the CLion compiler you will be deducted 25 points. Make sure your program works on that environment.
(25 Points) The program produces the correct output. Add 10 points if the output correctly goes to the file cal.dat.
(25 Points) The program specifications are followed.
(5 points) The year is validated upon entry. Only valid Gregorian calendars are printed.
(5 points)The program recognizes the leap year and handles it properly.
(5 points)The program starts the 1st on the correct day of the week.
(10 points)The program incorporates functions (more than 1) that pass values and returns values.
(10 Points)The program is documented (commented) properly with block comments above each function. Be sure to cite any reference where you used code.
(5 Points)Use constants when values are not to be changed
(5 Points)Use proper indentation
(5 Points)Use good naming standards
Sample Run:
Enter a valid year: 1955 1955 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
March 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
April 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
May 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
June 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
July 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
August 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
September 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
October 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
November 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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
