Question

Write a C# program that prints a calendar for a given year. Call this program calendar....

Write a C# 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 the functionality of each function and should display the instructions on how to run the program.

Your need to create one method “displayMonth” for print each month as required. You can choose return method or not that depend on your design.

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 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
..         ..          ..          ..          ..          ..          ..
..          ..

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Summary: Program Saved as Calendar.c

After running it ask for year, after entering year it will prompt for starting day( with suggestion) and display whole year calendar as required. "displaymonth" method is declared having no return type and with two parameter year and fday. Comments are placed to explain functionality

#include<stdio.h>

int mdays[]={31,28,31,30,31,30,31,31,30,31,30,31}; //Days in month for all 12 months
char *mname[]={"January","February","March","April","May","June","July","August","September","October",   "November",   "December"};

void displaymonth(int year, int fday)
{
   int month, day;
   for ( month = 0; month <= 11; month++ )
   {
       printf("%s", mname[month]);//Displaying month Name
       printf("\nSun Mon Tue Wed Thu Fri Sat\n" );//printing Day Headers
       for ( day = 1; day <= 1 + fday * 5; day++ )//adjustment for first day
       {
           printf(" ");
       }
       for ( day = 1; day <= mdays[month]; day++ )//printing all days in month
       {
           printf("%2d", day );
           if ( ( day + fday ) % 7 > 0 )//if first day is sunday start it on new line
               printf("   " );
           else
               printf("\n " );
       }
       printf("\n\n" );  
       fday = ( fday + mdays[month] ) % 7;//fday for next month
   }
}

int main(void)
{
   int year,fday;
   printf("Enter the year for which you wish to generate the calendar: ");
   scanf("%d", &year);
   printf("\nEnter the year for which you wish to generate the calendar: (0:Sunday 1:Monday 2:Tuesday 3:Wednesday 4:Thursday 5:Friday 6:Saturday): ");
   scanf("%d", &fday);
   if(year% 4 == 0 && year%100 != 0 || year%400 == 0)//checking for leap year
   {
       mdays[1] = 29;
   }
   else
   {
       mdays[1] = 28;
   }
   displaymonth(year,fday);//displaying each month
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a C# program that prints a calendar for a given year. Call this program calendar....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. 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:      ...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day ...

    C++ question Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day of the week you were born and how many days passed since you were born. Remember that January 1st of the year 2019 is Tuesday See the example below Read 1/1/2019 - Tue 90 Read 4/1/2019 - Mon 0 Read 4/1/2018 - Sun 365 Read 4/1/2017 -> Sat 730 Read 4/1/2016 Fri 1095 Read 4/1/2015-> Wed 1461 Bye... Wikipedia...

  • Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employ...

    Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employee works six days a week and takes the seventh day off. Days Mon Tue Wed Thu Fri Sat Sun Min. # of workers 6 9 How do yu forulaic: ihis problem The objective function? The constraints? Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employee works six days a week and takes the seventh day off. Days...

  • Customer Day Browser Time (min) 12.0 19.5 Pages Viewed Amount Spent (S) Mon Chrome Mon Chrome...

    Customer Day Browser Time (min) 12.0 19.5 Pages Viewed Amount Spent (S) Mon Chrome Mon Chrome Wed Chrome Sun Chrome 54.52 94.90 26.68 44.73 66.27 67.80 36.04 55.96 70.94 68.73 54.04 48.05 64.16 158.51 84.12 59.20 91.62 126.40 Wed Other Tue Firefox Sat Firefox 10.5 Fri Firefox Wed Firefox 12.7 24.7 13.3 Tue Chrome Sat Other Sun Firefox Sun Other Mon Firefox 12 13 24.4 Fri Chrome Thu Chrome Thu Chrome Mon Chrome Fri Other Wed Chrome 18 14.0 15.1...

  • #1.A For the full HeavenlyChocolates data set, fil in the wing table (to two decimals) ime...

    #1.A For the full HeavenlyChocolates data set, fil in the wing table (to two decimals) ime PagesAmt Spent Mean Standard Deviation Count Confidence Level( 99.0%) #1.B maintain/reject the null hypothesis that the mean value of Time is 12 min. at the .01 level because #1.C maintain/reject the null hypothesis that the mean value of Amt Spent is $70 at the .01 level because #2-A For the full HeavenlyChocolates data set, fill in the correlation table (to two decimals): Time PagesAmt...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...

  • please follow format of example output, do in python A year in the modern Gregorian Calendar...

    please follow format of example output, do in python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by...

  • Program 5: Design (pseudocode) and implement (source code) a program (name it Weekl yHours) to compute...

    Program 5: Design (pseudocode) and implement (source code) a program (name it Weekl yHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers' daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers between 0 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT