Answer:
//Annual calendar
#include <iostream>
#include <string>
#include <iomanip>
void month(int numDays, int day)
{
int i;
string weekDays[] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
// Header print
cout << "\n----------------------\n";
for(i=0; i<7; i++)
{
cout << left << setw(1) << weekDays[i];
cout << left << setw(1) << "|";
}
cout << left << setw(1) << "|";
cout << "\n----------------------\n";
int firstDay = day-1;
//Space print
for(int i=1; i< firstDay; i++)
cout << left << setw(1) << "|" << setw(2) << " ";
int cellCnt = 0;
// Iteration of days
for(int i=1; i<=numDays; i++)
{
//Output days
cout << left << setw(1) << "|" << setw(2) << i;
cellCnt += 1;
// New line
if ((i + firstDay-1) % 7 == 0)
{
cout << left << setw(1) << "|";
cout << "\n----------------------\n";
cellCnt = 0;
}
}
// Empty cell print
if (cellCnt != 0)
{
// For printing spaces
for(int i=1; i<7-cellCnt+2; i++)
cout << left << setw(1) << "|" << setw(2) << " ";
cout << "\n----------------------\n";
}
}
int main()
{
int i, day=1;
int yearly[12][2] = {{1,31},{2,28},{3,31},{4,30},{5,31},{6,30},{7,31},{8,31},{9,30},{10,31},{11,30},{12,31}};
string months[] = {"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};
for(i=0; i<12; i++)
{
//Monthly printing
cout << "\n Month: " << months[i] << "\n";
month(yearly[i][1], day);
if(day==7)
{
day = 1;
}
else
{
day = day + 1;
}
cout << "\n";
}
return 0;
}
//end