10.5k views
3 votes
Write a C++ program to display yearly calendar. You need to use the array defined below in your program. // the first number is the month and second number is the last day of the month. into yearly[12][2] =

User Peshal
by
7.5k points

1 Answer

1 vote

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 << "\\----------------------\\";

for(i=0; i<7; i++)

";

cout << left << setw(1) << "|";

cout << "\\----------------------\\";

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) << "

// Empty cell print

if (cellCnt != 0)

// For printing spaces

for(int i=1; i<7-cellCnt+2; i++)

cout << left << setw(1) << "

}

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 << "\\ Month: " << months[i] << "\\";

month(yearly[i][1], day);

if(day==7)

{

day = 1;

}

else

{

day = day + 1;

}

cout << "\\";

}

return 0;

}

//end

User Yep
by
6.4k points