欢迎光临散文网 会员登陆 & 注册

2022日历代码

2022-03-02 18:22 作者:大威的水杯  | 我要投稿

这个代码在周末时会变成红字,平常使用白字;

由于制作法定节假日和调休比较困难(其实就是up主懒),所以没有这个功能。

直接上代码:

#include <iostream>

#include <windows.h>


using namespace std;

void SetColorAndBackground(int ForgC, int BackC) 

{

WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);

}

int nextline(int i)

{

if (i == 1)

{

cout << endl;

cout << " ";

}

return 0;

}

int color(int x)

{

if (x == 6 || x == 7)

{

SetColorAndBackground(4, 0);

}

else

{

SetColorAndBackground(7, 0);

}

return 0;

}

int main(void)

{

int a, b, c, d;

cout << "2022年日历"<<endl;

d = 5;

for (a = 1; a <= 12; a++)

{

/*if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12)

{

c = 31;

}

else if (a == 4 || a == 6 || a == 9 || a == 11)

{

c = 30;

}

else

{

c = 28;

}

*/

cout << "|mon|tus|wen|thr|fri|sat|sun"<< endl ;

cout << "                ";

for (a = 1; a <= 12; a++)

{

cout << endl;

cout << a << "月日历";

cout << endl;

if (d == 1)

{

cout << "    ";

}

else if (d == 2)

{

cout << "       ";

}

else if (d == 3)

{

cout << "          ";

}

else if (d == 4)

{

cout << "             ";

}

else if (d == 5)

{

cout << "                ";

}

else if (d == 6)

{

cout << "                   ";

}

else

{

cout << "                      ";

}

if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12)

{

c = 31;

}

else if (a == 4 || a == 6 || a == 9 || a == 11)

{

c = 30;

}

else

{

c = 28;

}

for (b = 1; b <= c; b++)

{

if (d == 7)

{

d = 1;

}

else

{

d++;

}

nextline(d);

color(d);

cout << b << " ";

if (b < 10)

{

cout << " ";

}

}

}

}

}


2022日历代码的评论 (共 条)

分享到微博请遵守国家法律