显示日历

#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
  cout << "Enter a year: ";
  int year;
  cin >> year;


  cout << "Enter the first day of the year: ";
  int firstDay;
  cin >> firstDay;


  int numberOfDaysInMonth = 0;


  // Display calendar for each month
  for (int month = 1; month <= 12; month++)
  {
   
 // Display Calendar title
    switch (month)
    {
      case 1:
        cout << "January 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 2:
        cout << "Feburary 1, " << year << " is "<<endl;
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
          numberOfDaysInMonth = 29;
        else
          numberOfDaysInMonth = 28;
      break;
      case 3:
        cout << "March 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 4:
        cout << "April 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 30;
      break;
      case 5:
        cout << "May 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 6:
        cout << "June 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 30;
      break;
      case 7:
        cout << "July 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 8:
        cout << "August 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 9:
        cout << "September 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 30;
      break;
      case 10:
        cout << "October 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
      case 11:
        cout << "November 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 30;
      break;
      case 12:
        cout << "December 1, " << year << " is "<<endl;
        numberOfDaysInMonth = 31;
      break;
    }
cout<<setw(8)<<"SUN"<<setw(8)<<"MON"<<setw(8)<<"TUE"<<setw(8)<<"WED"<<setw(8)<<"SUR"<<setw(8)<<"FRI"<<setw(8)<<"SAT"<<endl;
     int n = 0;
int wrongfirstDay = firstDay;
for (int i  = 1;i<=numberOfDaysInMonth;i++)
     {
if(wrongfirstDay>0)
{
while(wrongfirstDay>0)
{ cout<<setw(8)<<" ";
       wrongfirstDay--;
n++;
}
cout<<setw(8)<<i;
n++;
if(n%7==0)
cout<<endl;
}
else
{
cout<<setw(8)<<i;
n++;
if(n%7==0)
cout<<endl;

}
 
     }
cout<<endl;
cout<<endl;
firstDay = (firstDay + numberOfDaysInMonth) % 7;




  
}
return 0;
}

你可能感兴趣的:(calendar,each,include,日历)