0% found this document useful (0 votes)
49 views6 pages

Sargun Singh Narula OOPM Assignment

This document contains a C++ program to print the calendar of 2021. It includes the following key elements: 1. Functions to determine the day of the week for a given date, get the month name as a string, and calculate the number of days in each month. 2. A 2D array to store holidays and important dates. 3. A printCalendar function that iterates through each month, prints the calendar layout including dates and holidays, and handles formatting. 4. Main calls printCalendar for 2021.

Uploaded by

Sargun Narula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

Sargun Singh Narula OOPM Assignment

This document contains a C++ program to print the calendar of 2021. It includes the following key elements: 1. Functions to determine the day of the week for a given date, get the month name as a string, and calculate the number of days in each month. 2. A 2D array to store holidays and important dates. 3. A printCalendar function that iterates through each month, prints the calendar layout including dates and holidays, and handles formatting. 4. Main calls printCalendar for 2021.

Uploaded by

Sargun Narula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SESSION 2020-21

ASSIGNMENT – III
REPORT
(Program to print Calendar of 2021)

SUBMITTED BY- SUBMITTED TO-


SARGUN SINGH NARULA PROF. FARHA HANEEF
CSE B
0105CS191101 HOD COMPUTER SCIENCE
OIST Bhopal OIST Bhopal
Question- To print the calendar of 2021. The program
should be such that it can print and highlight the holidays

Answer-
#include<stdlib.h>
#include<iostream>
using namespace std;
char* h[13][32];
int dayNumber(int day, int month, int year)
{ static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1,4, 6, 2, 4 };
year -= month < 3;
return ( year + year/4 - year/100 + year/400 + t[month-1] + day) % 7;
}
void addholidays(){
//add all the holidays in 2d array
int j=0,i=0;
for(i=0;i<13;i++)
for(j=0;j<32;j++)
h[i][j]=" ";
h[1][1]="(NewYear)",h[1][13]="(Lohri)",h[1][14]="(Pongal)",h[1][20]="(Sankranti)",
h[1][26]="(Republic Day)";h[2][14] ,h[2][16]="(Vasant panchmi)",
h[2][19]="(Shivajijay.)",h[2][27]="(Ravidas jay.)"; h[3][8]="(Maharishi jay.)",
h[3][11]="(Shivratri)",h[3][28]="(Holikadahana)",h[3][29]="(Holi)";
h[4][4]="(Easterday)",h[4][13]="(Sukhladi)",h[4][14]="(Vaisakhi)",
h[4][15]="(Ambedkar Jay)",h[4][21]="(Ram navami)",h[4][25]="(Mahavir Jay)";
h[5][1]="(May day)",h[5][9]="(Mother's d.)",h[5][14]="(Eid)",h[5][26]="(Buddha pur.)";
h[6][20]="(Father d.)",h[6][21]="(JuneSolstice)";
h[7][21]="(Bakra Eid)",h[7][24]="(Guru purnima)";
h[8][1]="(Friendshipd.)",h[8][15]="(Independenced.)",h[8][19]="(Muharram)",
h[8][21]="(Onam)",h[8][22]="(Rakhi)",h[8][30]="(Janmashtami)";
h[9][10]="(Ganesh chaturthi)";
h[10][2]="(Gandhijay.)",h[9][14]="(Navmi)",h[9][15]="(Dussehra)",
h[9][20]="(Valmiki jay.)";
h[11][4]="(Diwali)",h[11][6]="(Bhai duj)",h[11][10]="(chhat puja)",
h[11][19]="(Guru nanakjay.)"; h[12][25]="(Chirstmas)";
}
string getMonthName(int monthNumber)
{
string months[] = {"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
};
return (months[monthNumber]);
}
int numberOfDays (int monthNumber, int year)
{
// January
if (monthNumber == 0)
return (31);
// February
if (monthNumber == 1)
{
return (28);
}
// March
if (monthNumber == 2)
return (31);
// April
if (monthNumber == 3)
return (30);
// May
if (monthNumber == 4)
return (31);
// June
if (monthNumber == 5)
return (30);
// July
if (monthNumber == 6)
return (31);
// August
if (monthNumber == 7)
return (31);
// September
if (monthNumber == 8)
return (30);
// October
if (monthNumber == 9)
return (31);
// November
if (monthNumber == 10)
return (30);
// December
if (monthNumber == 11)
return (31);
}
// Function to print the calendar of the given year
void printCalendar(int year)
{
addholidays();

printf (" Calendar - %d\n\n", year);


int days;
// Index of the day from 0 to 6
int current = dayNumber (1, 1, year);
// i --> Iterate through all the months
// j --> Iterate through all the days of the
// month – i
for (int i = 0; i< 12; i++)
{
days = numberOfDays (i, year);

// Print the current month name


printf("\n ------------%s-------------\n",
getMonthName (i).c_str());
// Print the columns
printf(" Sun Mon Tue Wed Thu Fri Sat\n");
// Print appropriate spaces
int k;
for (k = 0; k < current; k++)
printf(" ");
for (int j = 1; j <= days; j++)
{
printf("%5d", j);
printf("%5s", h[i+1][j]);
if (++k > 6)
{
k = 0;
printf("\n");
}
}
if (k)
printf("\n");
current = k;
}
return;
}
// Driver Program to check above funtions
int main()
{
int year = 2021;
printCalendar(year);
return (0);
}

You might also like