用C++写了个简易的万年历。
具体功能如下:1.打印指定年(用户输入)所有月份的年历
2.打印指定年指定月(用户输入)的月份
3.打印指定日期(用户输入)的星期数
4.可重复输入
贴上源码:
#include<iostream>
#include<windows.h>
#include<iomanip>
using namespace std;
int number; //菜单键
int year, month, day; //年、月、日
int i, j, t; //for循环用的量
int s; //星期X
char c; //存放随机输入的数字,以实现“按任意键返回主菜单”的功能
char months[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; //平年每个月的天数
void Pos(int x, int y); //光标位置
void menu(); //主菜单函数
void runnian(); //如是闰年则变第二个月天数28为29
void oneyear(); //输出一整年的年历
void onemonth(); //输出一个月的月历
void xianshiweek(); //显示星期数
void Pos(int x, int y)//光标位置
{
COORD pos;
HANDLE hOutput;
pos.X = x;
pos.Y = y;
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOutput, pos);
}
void menu()//主菜单函数
{
Pos(40, 3);
cout << "***********************************" << endl;
Pos(40, 4);
cout << "* 欢迎使用万年历 *" << endl;
Pos(40, 5);
cout << "* ---made by pjr *" << endl;
Pos(40, 6);
cout << "*******************