程序控制结构2022-11-01

案例显示

#include 
#include 
using namespace std;
typedef enum { SUN, MON, THE, WED, THU ,FRI, SAT } WEEKDAY;
int main()
{
int date;
const WEEKDAY date_1 = FRI;
WEEKDAY weekday;
cout << "The program gets a date(1~31),and prints a calendar.\n";
cout << "The date: ";
cin >> date;
if( date < 1 || date > 31)
{
cout << "Date error!\n";
return 1;
}
weekday = (WEEKDAY)((date + (int)date_1 - 1) % 7);
cout << "Calendar 2022-12" << endl;
cout << "---------------------------------------\n";
cout << "Su    MO    Tu    We    Th    Fr    Sa\n";
cout << "---------------------------------------\n";
switch(weekday)
{
case SUN:
cout << setw(2) << date;
break;
case MON:
cout << setw(6) << date;
break;
case THE:
cout << setw(10) << date;
break;
case WED:
cout << setw(14) << date;
case THU:
cout << setw(18) << date;
break;
case FRI:
cout << setw(22) << date;
break;
case SAT:
cout << setw(26) << date;
break;
default:
 ;
}
cout << "\n---------------------------------------\n";
}
代码演示结果

你可能感兴趣的:(程序控制结构2022-11-01)