650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2015411128-0.gif "/> Perpetual calendar: records the calendar of a specific calendar or calendar date within a certain period of time, such as 100 or more, it is convenient for users who need it to query and use it.
When writing Perpetual calendar in C #, we should note that the calendar header and subject. Then, generate a specific function based on the expected data and write the function body completely. The last call is to generate the calendar of the year, which is the calendar month. Condition: Monday, January 1, January 1, 1900)
Note: When calculating the day of the week on the first day, calculate all the days before him;
Note the line feed for dates in each month;
Line feed is also required between every two months.
Using System; using System. collections. generic; using System. text; namespace prjPerCalender {public class MyCalender // my calendar class {static void Main (string [] args) {MyCalender r = new MyCalender (); // create a new object and give it a reference rr. printYearCalender (2013); // call the method of printing the year calendar to print the calendar of a specific year .} Public void PrintMonthCalender (int year, int month) // you can print a monthly calendar to obtain the monthly calendar. {PrintMonthHeader (year, month); // call the method for printing the header file of the monthly calendar. PrintMonthBody (year, month); // call the method for printing the subject of the monthly calendar .} Private void PrintMonthBody (int year, int month) // Method for printing the subject of the monthly calendar. {// Print the monthly calendar to get the number of days of the month. Call the calculation method to calculate the number of days of the month to get the number of days of the month. Int days = GetMonthDays (year, month); // you must know that the first day of each month is the day of the week, and call the method to obtain the first day of each month is the day of the week. Int week = GetWeekDayByFirstDayOfMonth (year, month); // the first day of each month is the day of the week, and a space is entered under the day before it. For (int I = 0; I <week; I ++) {Console. write ("\ t");} //, print each day of the month in sequence. If the number of week on the first day of the month equals 0 to 7, line feed is required. For (int I = 1; I <= days; I ++) {Console. write ("{0} \ t", I); if (I + week) % 7 = 0) {Console. write ("\ n") ;}// print the calendar of the next month by line after the calendar of each month is printed. Console. write ("\ n");} // The method of the day of the week on the first day of each month. private int GetWeekDayByFirstDayOfMonth (int year, int month) {// calculate the day of the week for the first day of a month. First, calculate the number of days from January 1, January 1, 1900 to the first day of the month. Int days = 0; // calculate the number of days of the year from January 1, 1900 to the Year to be calculated. For (int I = 1900; I <year; I ++) {days + = GetYearDays (I);} // calculate the number of days before January 1, 1st day of this month of the year. For (int I = 1; I <month; I ++) {days + = GetMonthDays (year, I );} // use the total number of days to calculate the remainder + 1 for 7 and then the remainder for 7 to obtain the number of the day of the week. Int week = (days % 7 + 1) % 7; // week is returned. return week;} // calculate the number of days in a year, which is 366 in a leap year and 365 in a year. private int GetYearDays (int year) {return IsLeapYear (year )? 366: 365;} // calculates the number of days in a month, such as, or, or, the day of the year of the leap. Private int GetMonthDays (int year, int month) {switch (month) {case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if (IsLeapYear (year) {return 29;} return 28; default: return 0 ;}} // determine whether this year is a leap year private bool IsLeapYear (int year) {return year % 4 = 0 & year % 100! = 0 | year % 400 = 0;} // print the header of the monthly calendar private void PrintMonthHeader (int year, int month) {// first output a month of a year, console. writeLine ("{0} year {1} month", year, month); // print the data from Sunday to Monday. Console. writeLine ("Sunday \ t Monday \ t Tuesday \ t Wednesday \ t Thursday \ t Friday \ t Saturday");} // print the annual calendar, print out the calendar for the past 12 months. Public void PrintYearCalender (int year) {for (int I = 1; I <13; I ++) {// call the method for printing the monthly calendar. PrintMonthCalender (year, I );}}}}
650) this. width = 650; "style =" float: none "title =" QQ201308080046562.png "src =" http://www.bkjia.com/uploads/allimg/131228/2015411463-1.png "/>
650) this. width = 650; "style =" float: none "title =" QQ201308080046091.png "src =" http://www.bkjia.com/uploads/allimg/131228/2015411623-2.png "/>
650) this. width = 650; "style =" float: none "title =" QQ20130808004523.png "src =" http://www.bkjia.com/uploads/allimg/131228/2015411454-3.png "/>
Have a good mood ...... 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2015411128-0.gif "/>
This article is from the "Lanting drunk beauty" blog and is not reposted!