Question
Write a C# console program that prints a calendar for a given year. Call this program calendar . The program prompts the user for two
Write a C# console program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:
1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week:
0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday
Your program should generate a calendar similar to the one shown in the example output below. The calendar should be printed on the screen. Your program should be able to handle leap years. A leap year is a year in which we have 366 days. That extra day comes at the end of February. Thus, a leap year has 366 days with 29 days in February. A century year is a leap year if it is divisible by 400. Other years divisible by 4 but not by 100 are also leap years.
Example: Year 2000 is a leap year because it is divisible by 400. Year 2004 is a leap year because it is divisible by 4 but not by 100.
Your program should clearly describe and display the instructions on how to run the program. It should run until the user want to quit, which you need to use dowhile loop as required. You also need to check input validation for correct input information (the day of week).
This program are required to use enumeration type for month title, and switch for display month days with correct form as show in example below.
Sample Input:
Enter the year for which you wish to generate the calendar: 2004 Enter the day of the week that January first is on: 4
Sample output:
Calendar for the year 2004
January 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 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 .. .. .. .. .. .. .. .. ..
Before main() method:
Create the enumeration type Month for the display month title.
main() method:
{
declare necessary variables
use to do...while loop to run the one-year calendar months and continue until the user wants to quit.
do
{
loop body:
prompt the user for year information input
prompt the user for the first day of January input
-need to check for input validation
Loop to go through each month: use loop statement (while or for)
loop for 12 time for the following steps:
Use switch statements for creating all 12 months with the days.
In February, you need to check for leap year to set up a correct number of days.
switch(month)
{
group case of months that has 31 days in the month for following actions
{
set the number of days in the month to 31
loop for beginning tabs before the output of day one of the month.
loop for printing the actual days of the month.
This loop ensures it will output the number of days inclusive and do a carriage return (next line)
when (start day + number of days) is a multiple of 7.
compute next month's start day
}
set next month's start day
break;
group case of months that has 30 days in the month for following actions
{
set the number of days in the month to 30
loop for beginning tabs before the output of day one of the month.
loop for printing the actual days of the month.
This loop ensures it will output the number of days inclusive and do a carriage return (next line)
when (start day + number of days) is a multiple of 7.
compute next month's start day
}
set next month's start day
break;
group case of February that has 28 or 29 days in the month for following actions
{
Check the leap year to set up the correct day in February for the years
if(is leap year)
set the number of days in the month to 29
else(not leap year)
set the number of days in the month to 28
loop for beginning tabs before output of day 1 of month.
loop for printing the actual days of the month.
This loop ensures it will output number of days inclusive and do a carriage return (next line)
when (start day + number of days) is a multiple of 7.
compute next month start day
}
set next month start day
break;
default case
}
prompt the user to continue or quit input
while(check the user continue or quit input);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started