还是关于C++的问题?

来源:百度知道 编辑:UC知道 时间:2024/05/19 18:37:06
请各位高手帮个忙.帮我编程一题作业?题目是:请编写一个程序,输出当年当月的月历?要求:按照周格式输出.例如,2005年7月的月历应该为:日 一 二 三 四 五 六
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
提示:1.假设已知本年1月1日是星期几,首先利用这个信息计算出将要输出的月份的第一天是星期几.
2.利用双重循环控制月历的输出格式.
哎哟 日期与星期不对齐了 1号应该对星期五,2号对星期六,三号对星期日,依次类推~~~~~~~~~~.麻烦大家了!行行好吧!谢谢!!

其实这样的东西一般都不怎么写,今中午无聊,就帮你搞定了吧,也许和你的要求有出入,你自己慢慢修改成自己需要的吧:
#include <iostream>
#include <cassert>
#include <numeric>
using namespace std;
// 08年1月1日为星期二

int dayNum[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
class CCal //calendar
{
private:
int m_month;
public:
CCal( int n = 1 );
public:
void print();
private:
int computeFirstPos();
};
CCal::CCal( int n ) /*:m_month(n)*/
{
assert( n>0&&n<13 );
m_month = n;
}
int CCal::computeFirstPos()
{
int n = accumulate( dayNum,dayNum + m_month-1,0 )%7 + 2;
if( n >= 7 )
n -=7;
return n;
}
void CCal::print()
{
int pos = computeFirstPos();
cout<<"日\t一\t二\t三\t四\t五\t六"<<endl;
int i = 1,n = pos;
while( n-- )
{
cout<<"\t";
}
while( i <=