636 lines
15 KiB
C++
636 lines
15 KiB
C++
#define _CRT_SECURE_NO_WARNINGS 1
|
||
#include<iostream>
|
||
#include<Windows.h>
|
||
#include<string>
|
||
#include<math.h>
|
||
#include<stdlib.h>
|
||
using namespace std;
|
||
//1.展示模块,需要将内容展示出来,告诉别人这是万年历
|
||
//2.输入模块,将数字展示出来
|
||
//3.检查模块,检查输入是否正确,防止小孩儿乱输入
|
||
//4.弹窗{需要将日历展示出来,首先将每一年排好顺序,其次,注意1582年有问题
|
||
//随后,将周六周天的日期,表示为红色
|
||
// }
|
||
// 换行问题()
|
||
// 分割问题()
|
||
//
|
||
//5.展示结束,国旗
|
||
int mo1(void);
|
||
int mo2(int n);
|
||
void mo3(int n);
|
||
int mo4(void);
|
||
void mo5(int n);
|
||
void mo6(int n);
|
||
void aixin(void);
|
||
int zhanshi(void);
|
||
int dan1(int n);
|
||
void dan2(int n);
|
||
void xingqi(int aa);
|
||
|
||
void color(short x) //自定义函根据参数改变颜色
|
||
{
|
||
if (x >= 0 && x <= 15)//参数在0-15的范围颜色
|
||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //只有一个参数,改变字体颜色
|
||
else//默认的颜色白色
|
||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
|
||
}
|
||
|
||
int bao(int n)
|
||
{
|
||
if (n > 1000000) {
|
||
cout << "输入越界,请重新输入"<<endl;
|
||
return zhanshi();
|
||
}
|
||
else cout << "输入成功" << endl;
|
||
}
|
||
int zifu(string a)
|
||
{
|
||
int n = 0;
|
||
if (a.size() > 4) {
|
||
cout << "输入错误,请重新输入" << endl;
|
||
return zhanshi();
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < a.size(); i++)
|
||
{
|
||
if (a[i] < '0' || a[i]>'9')
|
||
{
|
||
cout << "输入错误,请重新输入" << endl;
|
||
return zhanshi();
|
||
}
|
||
else
|
||
{
|
||
int p = a[i] - '0';
|
||
p = pow(10, a.size() - i - 1) * p;
|
||
n += p;
|
||
}
|
||
}
|
||
return n;
|
||
}
|
||
}
|
||
int zhanshi(void)
|
||
{
|
||
string n;
|
||
int i = 0;
|
||
int a = 0;
|
||
char b;
|
||
color(6);
|
||
cout << "Hello young people!!!" << endl;
|
||
cout << "------------------------------------------------------------------------------------------------------------------------" << endl;
|
||
cout << "------------------------------------------------------------------------------------------------------------------------" << endl;
|
||
cout << "------------------------------------------------------------------------------------------------------------------------" << endl;
|
||
cout << "This is a perpetual calendar!!!" << endl;
|
||
color(7);
|
||
cout << "它有很多功能" << endl;
|
||
color(3);
|
||
cout << "1.告诉你这一天是星期几" << endl;//完成
|
||
cout << "2.今天是否是一个适合表白的日子" << endl;//完成
|
||
cout << "3.输入某年的月历" << endl;
|
||
cout << "4.展示某一年的日历" << endl;
|
||
cout << "5.判断某一年是否为闰年" << endl;//完成
|
||
color(12);
|
||
cout << "如果程序弹出,说明输入错误" << endl;
|
||
color(7);
|
||
cout << "现在 请输入您需要的服务" << endl;
|
||
do {
|
||
Sleep(100);
|
||
//scanf("%c", &n);
|
||
cin >> n;
|
||
//getchar();
|
||
if (n.size() > 1) {
|
||
cout << "输入不符合规范,请重新输入" << endl;
|
||
return zhanshi();
|
||
}
|
||
else {
|
||
b = n[0];
|
||
if (b < 48 || b > 53) {
|
||
cout << "请重新输入!!!" << endl;
|
||
cout << "重新输入前,请输入换行" << endl;
|
||
i++;
|
||
}
|
||
if (i == 20) {
|
||
cout << "不会玩别玩了!!!" << endl;
|
||
break;
|
||
|
||
}
|
||
if (getchar() == '\n') {
|
||
a++;
|
||
|
||
}
|
||
if (a > 5) return 0;
|
||
}
|
||
} while (b < 48 || b>53);
|
||
switch (b-'0') {
|
||
case 1: mo1(); break;
|
||
case 2: mo2(b); break;
|
||
case 3: mo6(b); break;
|
||
case 4: mo4(); break;
|
||
case 5: mo5(b); break;
|
||
default: return 0;
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
int mo1(void)
|
||
{
|
||
int w;
|
||
string yy;
|
||
string mm;
|
||
string dd;
|
||
int ri[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
|
||
int y, m, d;
|
||
cout << "请输入年 月 日" << endl;
|
||
cin >> yy;
|
||
y = zifu(yy);
|
||
cin >> mm;
|
||
m = zifu(mm);
|
||
cin >> dd;
|
||
d = zifu(dd);
|
||
if (y == 1582 && m == 10) {
|
||
if (d < 15 && d>4) {
|
||
cout << "请重新输入" << endl;
|
||
return mo1();
|
||
}
|
||
}
|
||
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
|
||
ri[2] += 1;
|
||
}
|
||
if (y < 0 || y>10000 || m < 1 || m>12 || d < 1 || d > ri[m]) {
|
||
return mo1();
|
||
}
|
||
if (y == 1582 && m == 10 && d > 4) {
|
||
|
||
if (d > 4 && d < 15) {
|
||
cout << "请重新输入"<<endl;
|
||
return mo1();
|
||
}
|
||
d -= 10;
|
||
}
|
||
if (m == 1 || m == 2) {
|
||
m += 12;
|
||
y--;
|
||
}
|
||
w = (d + 1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
|
||
|
||
switch (w)
|
||
{
|
||
case 1:cout << "星期一[Monday]" << endl; break;
|
||
case 2:cout << "星期二[Tuesday]" << endl; break;
|
||
case 3:cout << "星期三[Wednesday]" << endl; break;
|
||
case 4:cout << "星期四[Thursday]" << endl; break;
|
||
case 5:cout << "星期五[Friday]" << endl; break;
|
||
case 6:cout << "星期六[Saturday]" << endl; break;
|
||
case 0:cout << "星期天[Sunday]" << endl; break;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
int mo2(int n)
|
||
{
|
||
string aa;
|
||
string mm;
|
||
string pp;
|
||
int a;
|
||
int m;
|
||
int p;
|
||
int ri[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
|
||
cout << "请输入年 月 日" << endl;
|
||
|
||
cin >> aa;
|
||
a=zifu(aa);
|
||
bao(a);
|
||
cin >> mm;
|
||
m = zifu(mm);
|
||
cin >> pp;
|
||
p = zifu(pp);
|
||
bao(m);
|
||
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0) {
|
||
ri[2] += 1;
|
||
}
|
||
if (m > 12 || m < 1) {
|
||
cout << "请重新输入" << endl;
|
||
return mo2(m);
|
||
}
|
||
bao(p);
|
||
if (p > ri[m] || p < 1) {
|
||
cout << "请重新输入" << endl;
|
||
return mo2(p);
|
||
}
|
||
if (m == 4 && p == 1) {
|
||
cout << "愚人节表白,建议换一个日子呢" << endl;
|
||
}
|
||
else if (m == 5 && p == 20 || p == 21) {
|
||
cout << "祝你成功!!!" << endl;
|
||
aixin();
|
||
}
|
||
else {
|
||
color(12);
|
||
cout << "不管你输入什么,都证明你有这样的想法" << endl;
|
||
cout << "勇敢的人有资格追求爱情,祝你成功!!!" << endl;
|
||
return 0;
|
||
}
|
||
return 0;
|
||
}
|
||
int mo4(void)
|
||
{
|
||
cout << "按1 单列输出" << endl;
|
||
cout << "按2 双列输出" << endl;
|
||
string aa;
|
||
int a;
|
||
cin >> aa;
|
||
a = zifu(aa);
|
||
bao(a);
|
||
if (a > 2 || a < 1) {
|
||
cout << "输入失败,请重新输入" << endl;
|
||
}
|
||
switch (a)
|
||
{
|
||
case 1:dan1(a); break;
|
||
case 2:dan2(a); break;
|
||
default:return mo4(); break;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
void mo5(int n)
|
||
{
|
||
string aa;
|
||
int a;
|
||
cout << "请输入年份" << endl;
|
||
cin >> aa;
|
||
a = zifu(aa);
|
||
/* n = 0;
|
||
if (a.size() > 4) return;
|
||
else
|
||
{
|
||
for (int i = 0; i < a.size(); i++)
|
||
{
|
||
if (a[i] < '0' || a[i]>'9')
|
||
{
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
int p = a[i] - '0';
|
||
p = pow(10, a.size() - i - 1) * p;
|
||
n+=p;
|
||
}
|
||
}
|
||
}
|
||
*/
|
||
if (n % 4 == 0 && n % 100 != 0 || n % 400 == 0) {
|
||
cout << "是闰年" << endl;
|
||
}
|
||
else cout << "不是闰年" << endl;
|
||
}
|
||
|
||
void mo6(int n)
|
||
{
|
||
int d;
|
||
string yy;
|
||
string mm;
|
||
int y, m;
|
||
int w;
|
||
int t;
|
||
int j;
|
||
int ri[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
|
||
|
||
/* printf("_________________________________________\n");
|
||
printf(" 周日 周一 周二 周三 周四 周五 周六 \n");
|
||
printf("_________________________________________\n");*/
|
||
//判断1号为周几
|
||
//将1号之前的数输出空格
|
||
//scanf(%6d,&d);
|
||
//到七就换行;
|
||
//输出1
|
||
//输出2到31
|
||
//先输入
|
||
cout << "请输入年 月" << endl;
|
||
cin >> yy;
|
||
y = zifu(yy);
|
||
cin >> mm;
|
||
m = zifu(mm);
|
||
bao(y);
|
||
bao(m);
|
||
if (m > 12 || m < 1) {
|
||
return mo6(m);
|
||
}
|
||
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
|
||
ri[2] += 1;
|
||
}
|
||
j = m;
|
||
if (m == 1 || m == 2) {
|
||
m += 12;
|
||
y--;
|
||
}
|
||
w = (1 + 1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;//
|
||
printf("_________________________________________\n");
|
||
printf(" 周日 周一 周二 周三 周四 周五 周六 \n");
|
||
printf("_________________________________________\n");
|
||
for (int i = 0; i < w; i++) {
|
||
cout << " ";
|
||
}
|
||
|
||
t = w;
|
||
if (y == 1582 && m == 10) {
|
||
for (int i = 1; i <= 4; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
}
|
||
for (int i=15; i <= ri[j]; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
}
|
||
}
|
||
else {
|
||
for (int i = 1; i <= ri[j]; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
void aixin(void)
|
||
{
|
||
color(12);
|
||
float x, y, a;
|
||
for (y = 1.5f; y > -1; y -= 0.1f) {
|
||
for (x = -1.5f; x < 1.5f; x += .05f) {
|
||
a = x * x + y * y - 1;
|
||
putchar(a * a * a - x * x * y * y * y < 0.0f ? '*' : ' ');
|
||
}
|
||
Sleep(15);
|
||
putchar('\n');
|
||
}
|
||
return;
|
||
|
||
}
|
||
|
||
int dan1(int n)
|
||
{
|
||
int y, m, d;
|
||
string yy;
|
||
int w;
|
||
int t;
|
||
int ri[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
|
||
cout << "请输入年份" << endl;
|
||
//scanf("%d", &y);
|
||
cin >> yy;
|
||
y = zifu(yy);
|
||
bao(y);
|
||
for (int j = 1; j < 13; j++) {
|
||
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
|
||
ri[2]++;
|
||
}
|
||
m = j;
|
||
if (m == 1 || m == 2) {
|
||
m += 12;
|
||
y--;
|
||
}
|
||
w = (1 + 1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
|
||
printf("_________________________________________\n");
|
||
printf(" %d月 \n", j);
|
||
printf("_________________________________________\n");
|
||
printf(" 周日 周一 周二 周三 周四 周五 周六 \n");
|
||
printf("_________________________________________\n");
|
||
for (int i = 0; i < w; i++) {
|
||
cout << " ";
|
||
}
|
||
|
||
t = w;
|
||
if (y == 1582 && j == 10) {
|
||
for (int i = 1; i <= 4; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
if (i == ri[j])cout << endl;
|
||
}
|
||
for (int i = 15; i <= ri[j]; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
if (i == ri[j])cout << endl;
|
||
}
|
||
}
|
||
else {
|
||
for (int i = 1; i <= ri[j]; i++) {
|
||
if (t == 7) {
|
||
cout << endl;
|
||
t = 0;
|
||
}
|
||
printf("%5d", i);
|
||
t++;
|
||
if (i == ri[j])cout << endl;
|
||
}
|
||
ri[2] = 28;
|
||
if (m == 13 || m == 14) {
|
||
y++;
|
||
}
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
void xingqi(int aa)
|
||
{
|
||
//int j = 1;
|
||
for (int i = 0; i < 2; i++) {
|
||
printf("_________________________________________\t");
|
||
}
|
||
cout << "\n";
|
||
for (int i = 0; i < 2; i++) {
|
||
printf(" %d月 \t", aa++);
|
||
}
|
||
cout << "\n";
|
||
for (int i = 0; i < 2; i++) {
|
||
printf("_________________________________________\t");
|
||
}
|
||
cout << "\n";
|
||
for (int i = 0; i < 2; i++) {
|
||
printf(" 周日 周一 周二 周三 周四 周五 周六 \t\t");
|
||
}
|
||
cout << "\n";
|
||
for (int i = 0; i < 2; i++) {
|
||
printf("_________________________________________\t");
|
||
}
|
||
cout << "\n";
|
||
return;
|
||
}
|
||
|
||
void dan2(int n)
|
||
{
|
||
cout << "请输入年份";
|
||
cout << endl;
|
||
int y;
|
||
string yy;
|
||
cin >> yy;
|
||
y = zifu(yy);
|
||
bao(y);
|
||
//////////////
|
||
int aa = 1;
|
||
int bb = 2;
|
||
//////////////
|
||
int m = 1;
|
||
int a = 1;
|
||
int b = 1;
|
||
int c = 1;
|
||
int tt = 6;
|
||
int d = 35;
|
||
//int w;
|
||
int ri[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
|
||
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
|
||
ri[2]++;
|
||
}
|
||
int w;//将一号的位置存起来
|
||
int ww[13] = { 0 };
|
||
int t[13] = { 0 };
|
||
for (m = 1; m < 13; m++) {
|
||
if (m == 1 || m == 2) {
|
||
m += 12;
|
||
y--;
|
||
}
|
||
w = (1 + 1 + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
|
||
ww[a] = w;
|
||
a++;
|
||
if (m == 13 || m == 14) {
|
||
m -= 12;
|
||
y++;
|
||
}
|
||
}//地址存入成功
|
||
for (int i = 1; i < 13; i++) {
|
||
t[i] = ww[i];
|
||
}
|
||
for (aa = 1, bb = 2; aa <= 11, bb <= 12; aa += 2, bb += 2) {
|
||
tt = 6;
|
||
b = 1;
|
||
c = 1;
|
||
xingqi(aa);
|
||
while (tt--) {
|
||
if (tt == 5) {
|
||
for (int i = 0; i < ww[aa]; i++) {
|
||
printf(" ");
|
||
}
|
||
}
|
||
for (; b <= ri[aa]; b++) {
|
||
printf("%5d", b);
|
||
t[aa]++;
|
||
if (t[aa] == 7) {
|
||
t[aa] = 0;
|
||
cout << "\t\t";
|
||
break;
|
||
}
|
||
}
|
||
b++;
|
||
if (t[aa] != 0) {
|
||
|
||
for (; t[aa] < 7; t[aa]++)
|
||
cout << " ";
|
||
cout << "\t\t";
|
||
}
|
||
if (tt == 0)
|
||
if (b > ri[aa]) {
|
||
cout << " \t\t\t\t";
|
||
}
|
||
if (tt == 5) {
|
||
for (int i = 0; i < ww[bb]; i++) {
|
||
printf(" ");
|
||
}
|
||
}
|
||
if (y == 1582 && bb == 10) {
|
||
for (; c <= ri[bb]; c++) {
|
||
if (c == 5) {
|
||
c += 10;
|
||
}
|
||
printf("%5d", c);
|
||
t[bb]++;
|
||
if (t[bb] == 7) {
|
||
t[bb] = 0;
|
||
printf("\n");
|
||
break;
|
||
}
|
||
}
|
||
if (c > ri[bb])cout << "\n";
|
||
}//////////////////////////
|
||
else for (; c <= ri[bb]; c++) {
|
||
printf("%5d", c);
|
||
t[bb]++;
|
||
if (t[bb] == 7) {
|
||
t[bb] = 0;
|
||
printf("\n");
|
||
break;
|
||
}
|
||
}//结束循环,执行\n
|
||
c++;
|
||
|
||
if (tt == 0) {
|
||
cout << "\n";
|
||
}
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
int main(void)
|
||
{
|
||
color(7);
|
||
string a;
|
||
int f=zhanshi();
|
||
color(7);
|
||
if (f)
|
||
{
|
||
//system("cls");
|
||
cout << "\n您是否想尝试其他模块?" << endl;
|
||
cout << "如果是的话,请输入YES" << endl;
|
||
cout << "如果不想尝试的话,请输入NO" << endl;
|
||
}
|
||
else
|
||
cout << "Bye Bye"<<endl;
|
||
//cin >> a;
|
||
getchar();
|
||
getline(cin, a);
|
||
system("cls");
|
||
if (a == "YES") {
|
||
cout << "OK" << endl;
|
||
main();
|
||
}
|
||
else if (a == "NO") {
|
||
cout << "再见!!!" << endl;
|
||
}
|
||
else {
|
||
cout << "不会玩别玩了!!!" << endl;
|
||
return 0;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|