6+ CPP Calendar Programs

This post contains a total of 6+ CPP Calendar Program Examples with Source Code. All these Calendar Programs are made using C++.

You can use the source code of these examples with credits to the original owner.

CPP Calendar Programs

1. MONTHLY ENGLISH CALENDAR 2021

Made by Jawa. Source

Enter the month in number [0 - 12]:5



               MAY โ€” 2021

 =======================================
 MO ยฆยฆ TU ยฆยฆ WE ยฆยฆ TH ยฆยฆ FR ยฆยฆ SA ยฆยฆ SU 
 --------------------------------------
 X  || X  || X  || X  || X  || 01 || 02
 ---------------------------------------
 03 || 04 || 05 || 06 || 07 || 08 || 09
 ---------------------------------------
 10 || 11 || 12 || 13 || 14 || 15 || 16
 ---------------------------------------
 17 || 18 || 19 || 20 || 21 || 22 || 23
 ---------------------------------------
 24 || 25 || 26 || 27 || 28 || 29 || 30
 ---------------------------------------
 31 ||  =======================================
/* ENTER THE MONTH'S  NO TO GET OUTPUT [1-12] || if you want full calendar [ENTER 0๏ธโƒฃ]----.
(FOR EXAMPLE:5, IT GIVES THE MONTH MAY AS OUTPUT.  0, IT GIVES FULL CALENDAR)
*/

#include <iostream>
using namespace std;
void top(int mon){
    cout<<endl<<endl<<endl;
string month[12]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
int j=0;
if(mon!=0){
while(true){
    if(mon==(j+1)){
        cout<<endl<<"               "<<month[j]<<" โ€” 2021";
        break;
    }
    else{
    j++;
    continue ;} 
}}
cout<<endl<<endl;
for(int sk=0;sk<40;sk++){
    if(sk!=0)
                cout<<'=';
                else
                cout<<' ';}
                cout<<endl;
cout<<" MO ยฆยฆ TU ยฆยฆ WE ยฆยฆ TH ยฆยฆ FR ยฆยฆ SA ยฆยฆ SU "<<endl;
for(int sk=0;sk<39;sk++){
if(sk!=0)
                cout<<'-';
                else
                cout<<' ';}
                cout<<endl;
    
    
    
}
int func(int tot,int cp,int sp,int mon,int n,int date){
    if(cp<sp){
        while(cp<sp)
        {
            if(cp==0){
            if(mon==n||mon==0){
                cout<<" ";}
                cp++;
            }
            if(cp<sp){
                if(mon==n||mon==0){
                cout<<"X  || ";}
                cp+=6;
            }
        }
    }
/*----------------------------------*/
if(sp<=cp){
    while(date<=tot){
        if(cp==37){
            if((date/10)<1){
                if(mon==n||mon==0){
                cout<<'0'<<date;}
                date++;
            }
            else{
                if(mon==n||mon==0){
                    cout<<date;
                }
                date++;
            }
            if(mon==n||mon==0){
            cout<<endl<<' ';}
            cp=1;
            if((mon==n||mon==0)){
                for(int sk=0;sk<39;sk++){
                cout<<'-';}
                cout<<endl;
                cout<<' ';
                sp=0;
            }}
            else{
                if((date/10)<1){
                    if(mon==n||mon==0){
                        cout<<'0'<<date<<" || ";
                    }
                    date++;cp+=6;
                }
                else{
                if(mon==n||mon==0){
                cout<<date<<" || ";}
       
            date++;
            cp+=6;}
        }        
       
}}
if(mon==n){
    for(int sk=0;sk<40;sk++){
    if(sk!=0)
                cout<<'=';
                else
                cout<<' ';}
                
}
if(cp>37)
cp=1;
return cp;}
int main() {
int mon;
while(true){
cout<<"\nEnter the month in number [0 - 12]:";
cin>>mon;
if(mon>=0&&mon<13){
cout<<mon;
    break;}
    else{
    cout<<"\nEnter valid number:";
    break;
}}
int cp=0,sp=0,tot=0,date=1,n=1;
    if(mon==1||mon==0){
    sp=25;}   
    while(true){
     if(n==1||n==3||n==5||n==7||n==8||n==10||n==12){
tot=31;}
else if(n==2)
tot=28;
else
tot=30;
date=1;
    cp=0;
    if(mon==0)
    top(n);
    else if(mon==n){
        top(n);
    }
    sp=func(tot,cp,sp,mon,n,date);
    if(mon==0){
        for(int sk=0;sk<41;sk++){
    if(sk==0){
                cout<<"  ";}
                else
                cout<<'=';}
    }
    if(mon==0&&n<12){
    n++;}
   else if(mon==n||n==12)
    break;
    else
    {
        n++;
        continue;
    }
}
cout<<endl<<endl<<endl<<"************BY JAWAHIRULLAH************"<<endl<<endl<<"check your calendar if it is right or wrong ๐Ÿ—“๏ธ"<<endl<<endl<<"[pls hit like(upvote) and comment me how is it.]";
    return 0;
}

2. Calendar of 2017

Made by Deepthi Vemula. Source

2017
JANUARY
S  1  8 15 22 29 
M  2  9 16 23 30 
T  3 10 17 24 31 
W  4 11 18 25 
T  5 12 19 26 
F  6 13 20 27 
S  7 14 21 28 

FEBRUARY
S     5 12 19 26 
M     6 13 20 27 
T     7 14 21 28 
W  1  8 15 22 
T  2  9 16 23 
F  3 10 17 24 
S  4 11 18 25

...
#include<iostream>
void skiptoday(int);
int nodays(int m);
void printheader(int);
int printmon(int,int);
using namespace std;
int main()
{    cout<<"2017\n";
    int currmon=1,weekday=0;
    while(currmon<=12)
    {
        int numdays=nodays(currmon);
    weekday=printmon(numdays,weekday);
        cout<<endl;
        currmon++;
    }cout<<endl<<endl;
    return 0;
}
int nodays(int m)
{
    if(m==1)
    {
        cout<<"JANUARY\n";
        return 31;
    }
    else if(m==2)
    {
        cout<<"FEBRUARY\n";
        return 28;
    }
    else if(m==3)
    
    {
        cout<<"MARCH\n";
        return 31;
    }
    else if(m==4)
    {
        cout<<"APRIL\n";
        return 30;
    }
    else if(m==5)
    {
        cout<<"MAY\n";
        return 31;
    }
    else if(m==6)
    {
        cout<<"JUNE\n";
        return 30;
    }
    else if(m==7)
    {
        cout<<"JULY\n";
        return 31;
    }
    else if(m==8)
    {
        cout<<"AUGUST\n";
        return 31;
    }
    else if(m==9)
    
    {
        cout<<"SEPTEMBER\n";
        return 30;
    }
    else if(m==10)
    {
        cout<<"OCTOBER\n";
        return 31;
    }
    else if(m==11)
    {
        cout<<"NOVEMBER\n";
        return 30;
    }
    else if(m==12)
    {
        cout<<"DECEMBER\n";
        return 31;
    }

}
/*
{
    cout<<" S  M  T  W  T  F  S \n";
    cout<<"_______________________\n";
}*/
int printmon(int numdays,int weekday)
{
    int day=0; 
    int i=1;
    int p,k,d=1;
    for(day=0;day<7;day++)
    {
        if(day==0)
        cout<<"S ";
        else if(day==1)
        cout<<"M ";
        else if(day==2)
        cout<<"T ";
        else if(day==3)
        cout<<"W ";
        else if(day==4)
        cout<<"T ";
        else if(day==5)
        cout<<"F ";
        else if(day==6)
        cout<<"S ";
        if(day<weekday)
        cout<<"   ";
        else if(day>=weekday)
        {
        cout<<" "<<d<<" ";
        d++;}
        k=0;
        /*initially for printing a horizontal row
        as we have printed dates in 1st column we have to go for 2nd column
        for that (7-weekday+i+k) becomes the date of next column in the same row i and weekday are increased every time we move for next row
    to calculate the next number in the same row 7 is to be added to existing number and it is to be printed till the date is <= number of days in that month
        
        */
        while((7-weekday+i+k)<=numdays)
        {
        /* this (7-weekday+i+k) is checked for some general months and obtained
        */
            if((7-weekday+i+k)<10)
            cout<<" ";
            cout<<7-weekday+i+k<<" ";
            if((7-weekday+i+k) == numdays)
            p=day;
            k+=7;
        }
        i++;
        cout<<endl;
        
    }
    weekday=p+1;
    if(weekday==7)
    weekday=0;
    return weekday;

}

3. Calendar of year without time.h/ctime

Made by Wojciech Bruski. Source

Enter year: 2022
Calendar of year 2022
	* January *
Mon Tue Wed Thr Fri Sat Sun
                      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 

	* February *
Mon Tue Wed Thr Fri Sat Sun
      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


............
#include <iostream>

using namespace std;

//Names of months
const string months[12] =
    {
       "January",
       "February",
       "March",
       "April",
       "May",
       "June",
       "July",
       "August",
       "September",
       "October",
       "November",
       "December"
    };
//Year of calendar
int year;
//Number of day and day of the week
int dow = 0;

//count day of month
int count_days(int month)
{
    switch(month)
    {
       case 1:
       case 3:
       case 5:
       case 7:
       case 8:
       case 10:
       case 12: return 31; break;
       
       case 4:
       case 6:
       case 9:
       case 11: return 30; break;
       
       case 2: return (year%4==0)?29:28; break;
       
       default: return 0; break;
    }
}

int main() {
    cout << "Enter year: ";
    cin >> year; cout << endl;

    /*if(year < 1900)
    {
        cout << "Wrong year!" << endl;
        return -1;
    }*/
//Calculate day of the week for date 1/1/year
    if(year>1900)
    {
        for(int i=1900 ; i<year ; i++)
        {
            dow += (i%4==0)?2:1;
        }
        
        dow--;
    }else if(year<1900)
    {
        for(int i=1900 ; i>year ; i--)
        {
            dow += (i%4==1)?2:1;
        }
    }else if(year<=0)
    {
        dow=2;
        
        for(int i=0 ; i>year ; i--)
        {
            dow += (i%4==1)?2:1;
        }
    }
    dow %= 7;
    if(year<1900) dow = 7-dow;
    
//Print calendar on screen
    cout << "Calendar of year ";
    if(year<0) cout << -year << " BC\n";
    else cout << year << endl;

    for(int m=0 ; m<12 ; m++)
    {
        cout << "\t* " << months[m] << " *" << endl;
        cout << "Mon Tue Wed Thr Fri Sat Sun\n";
        
        for(int i=0 ; i<dow ; i++)
            cout << "    ";
        
        for(int d=1 ; d<=count_days(m+1) ; d++)
        {
            if(d<10) cout << "  " << d << " ";
            else cout << " " << d << " ";
            
            if(++dow % 7 == 0)
            {
                cout << endl;
                dow%=7;
            }
                
        }
        
        cout << "\n\n";
    }
    
    return 0;
}

4. Calendar Printer

Made by Kinshuk Vasisht. Program to print a calendar for a given month and year. Source

12
2000

                Calendar
                --------

       December, 2000


       S   M   T   W   T   F   S
     - - - - - - - - - - - - - - - 

                           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  
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>

#define tendl endl<<endl<<endl
using namespace std;

string mname(int m)
{
    string spc = "       ";
    if(m== 1) return spc+"January";
    if(m== 2) return spc+"February";
    if(m== 3) return spc+"March";
    if(m== 4) return spc+"April";
    if(m== 5) return spc+"May";
    if(m== 6) return spc+"June";
    if(m== 7) return spc+"July";
    if(m== 8) return spc+"August";
    if(m== 9) return spc+"September";
    if(m==10) return spc+"October";
    if(m==11) return spc+"November";
    if(m==12) return spc+"December";
    if(m>12) exit(0);
}

int day_of_week(int day,int month, int year)
{
    int lpyr,yr,ody,odm=0,odd,flag=0,ods;
    int mnth[12] = {31,28,31,30,31,30,31,
                    31,30,31,30,31};
    if(year<100)
    { if(year%4==0) flag=1; }
    else
    {
        if(year%400==0)      flag=1;
        else if(year%100==0) flag=0;
        else if(year%4==0)   flag=1;
    }
    if(flag==1) mnth[1]=29;
    lpyr=(year-1)/4; yr=year-1-lpyr;
    ody=(lpyr*366)+(yr*365);
    for(int i=1;i<month;i++) odm+=mnth[i-1];
    odd=(day-1); ods=odd+odm+ody;
    return ods%7;
}
int main(void)
{
    cout<<setw(24)<<right<<"Calendar"<<endl;
    cout<<setw(24)<<right<<"--------"<<endl;
    int yr,mth,flag=0,day=1,mk;
    int m[12] = {31,28,31,30,31,30,
                 31,31,30,31,30,31};
    cin>>mth;cin>>yr;
    if(yr<100) { if(yr%4==0) flag=1; }
    else
    {
        if(yr%400==0)      flag=1;
        else if(yr%100==0) flag=0;
        else if(yr%4==0)   flag=1;
    }
    if(flag==1) m[1]=29;
    mk=day_of_week(1,mth,yr);
    cout<<endl<<mname(mth)<<", "<<yr<<tendl;
    cout<<"       S   M   T   W  "
        <<" T   F   S\n";
    cout<<"     - - - - - - - - -"
        <<" - - - - - - \n\n";
    for(int i=1;i<=6;i++)
    {
        cout<<(day<10?"       ":"      ");
        for(int j=1;j<=7;j++)
        {
            if(day<=m[mth-1])
            {
                if(mk==0)
                {
                    if(day<=m[mth-1])
                    cout<<day<<\
                    (day<9?"   ":"  ");
                    else
                    cout<<" "<<"   ";
                    day++;
                 }
                 else if(mk==1)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
                 else if(mk==2)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
                 else if(mk==3)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
                 else if(mk==4)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
                 else if(mk==5)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
                 else if(mk==6)
                 {
                    cout<<" "<<"   ";
                    mk--;
                 }
             }
        }
        cout<<endl<<endl<<endl;
    }
    cout<<endl<<endl;
}

5. 2021 Calendar

Made by Chillpill. Source

      Jan 2021
  s  m  t  w  t  f  s  
                 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

       Feb 2021
  s  m  t  w  t  f  s  
     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


.........
#include <iostream>
#include <iomanip>
using namespace std;

int dowJanuaryFirst(const int & year){
    return (1+(5*((year-1)%4))+
    (4*((year-1)%100))+(6*((year-1)%400)))%7;
}

bool isLeapYear(const int & year){
    if(year<=1582)     return false;
    if(year%400==0)    return true;
    if(year%100==0)    return false;
    if(year%4==0)      return true;
    return false;
}

int daysInMonth(const int & month, bool leap=0){
    if(month==1)    return 28 + leap;
    if(month<7)     return (month%2)?30:31;
    return (month%2)?31:30;
}

void calendar(const int & year){
    int day = dowJanuaryFirst(year);
    bool leap = isLeapYear(year);
    const string months[12]{
        "Jan","Feb","Mar","Apr","May","Jun",
        "Jul","Aug","Sep","Oct","Nov","Dec"
    };
    const char dow[8]="smtwtfs";
    for(int i=0;i<12;++i){
        cout<<"\n\n"<<setw(10)
            <<months[i]<<" "<<year<<endl;
        for(const char & c:dow)
            cout<<setw(3)<<c;
        cout<<endl;
        const int days = daysInMonth(i,leap);
        cout<<string(3*day,' ');
        for(int i=1;i<=days;++i){
            cout<<setw(3)<<i;
            if(++day%7==0&&i!=days) cout<<endl;
            day%=7;
        }
    }
}

int main() {
    for(int year{2021};year<2060;++year)
    calendar(year);
    return 0;
}

6. Simple CPP Calendar

Made by ุฃุญู…ุฏ. Source

2022 calendar is

January
_____
Sun Mond Tues Wend Thur Frid Sat

                               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   

February
_____
Sun Mond Tues Wend Thur Frid Sat

           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

.........
#include <iostream>
#include <iomanip>
using namespace std;
int year;
//*************************************
void printMontName(int m){
    if(m==1){
        cout <<"January"<<endl;
        cout<<"_____"<<endl;}
        else if(m==2){
        cout <<"February"<<endl;
         cout<<"_____"<<endl;  }
     else if(m==3){
        cout <<"March"<<endl;
         cout<<"_____"<<endl;  }
     else if(m==4){
        cout <<"April"<<endl;
        cout<<"_____"<<endl; }
     else if(m==5){
        cout <<"May"<<endl;
         cout<<"___"<<endl; }
     else if(m==6){
        cout <<"June"<<endl;
        cout<<"_____"<<endl; }
     else if(m==7){
        cout <<"July"<<endl;
         cout<<"___"<<endl; }
     else if(m==8){
        cout <<"Augustt"<<endl;
          cout<<"___"<<endl; }
     else if(m==9){
        cout <<"September"<<endl;
         cout<<"________"<<endl; }
     else if(m==10){
        cout <<"October"<<endl;
         cout<<"______"<<endl; }
     else if(m==11){
        cout <<"November"<<endl;
        cout<<"________"<<endl; }
     else if(m==12){
        cout <<"December"<<endl;
         cout<<"______"<<endl; }
cout<<"Sun Mond Tues Wend Thur Frid Sat"<<endl<<endl;
       }
 //*************************************         
int numberDaysInMonth( int m){
    if(m==1){
        return (31);
    }
    else if(m==2){
if((year%400==0||year%4==0)&&(year%100!=0)){
      return(29);}
      else return (28);
     }
     else if(m==3){
         return(31); 
         }
         else if(m==4){
         return(30);
          }
         else if(m==5){
         return(31); 
         }
         else if(m==6){
         return(30);
          }
         else if(m==7){
         return(31);
          }
         else if(m==8){
         return(31); 
         }
         else if(m==9){
         return(30); 
         }
         else if(m==10){
         return(31); 
         }
         else if(m==11){
         return(30); 
         }
         else if(m==12){
         return(31); 
         }
    }
 //*************************************   
int beginnigDayOfNewYear(int year){
      int f;
      int x= year%100;
      int y=x/12;
      int z=x%12;
      int w=z/4;
 if((year%400==0||year%4==0)&&(year%100!=0)){   f=(y+z+w-3)%7;
        }
        else {
            f=(y+z+w-2)%7;
        }
        return f;
        } 
//*************************************      
int weekDay ; 
int startD(int year) {
   if(year>=1900&&year<2000){
   weekDay=(beginnigDayOfNewYear(year)+3)%7;    }
   else if( year>=2000&&year<2100 ){
   weekDay=(beginnigDayOfNewYear(year)+2)%7;            
       }
       return weekDay;
   }
//*************************************   
 void printDaysOfMonth(int nmDaysInMonth,int &startDay){
     int day=1;
     int i=1;
     while(i<=startDay){
         cout<<"     ";
         i++;
     }
     while(day<=nmDaysInMonth){
         cout<<setw(2)<<day<<"   ";
          if(startDay==6){
             cout <<endl;
             startDay=0;
             day++;
           }
          else{
          startDay++;
         day++ ;  
       }
    }
 }
//***************************************    
int main() { 
cin>>year;
cout<<year<<" calendar is"<<endl<<endl;
int startDay =startD(year);
int currentMonth=1;
while (currentMonth<=12){
int nDaysInMonth= numberDaysInMonth(currentMonth);
printMontName(currentMonth);
printDaysOfMonth(nDaysInMonth,startDay);
cout<<endl<<endl;
currentMonth++;
   }  
    return 0;
}

7. Calendar (french)

Made by Chillpill. Source

     Jan 2021
  d  l  m  m  j  v  s  
                 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

       Fev 2021
  d  l  m  m  j  v  s  
     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


.........
#include <iostream>
#include <iomanip>
using namespace std;

int dowJanuaryFirst(const int & year){
    return (1+(5*((year-1)%4))+
    (4*((year-1)%100))+(6*((year-1)%400)))%7;
}

bool isLeapYear(const int & year){
    if(year<=1582)     return false;
    if(year%400==0)    return true;
    if(year%100==0)    return false;
    if(year%4==0)      return true;
    return false;
}

int daysInMonth(const int & month, bool leap=0){
    if(month==1)    return 28 + leap;
    if(month<7)     return (month%2)?30:31;
    return (month%2)?31:30;
}

void calendar(const int & year){
    int day = dowJanuaryFirst(year);
    bool leap = isLeapYear(year);
    const string months[12]{
        "Jan","Fev","Mar","Avr","Mai","Jun",
        "Jul","Aou","Sep","Oct","Nov","Dec"
    };
    const char dow[8]="dlmmjvs";
    for(int i=0;i<12;++i){
        cout<<"\n\n"<<setw(10)
            <<months[i]<<" "<<year<<endl;
        for(const char & c:dow)
            cout<<setw(3)<<c;
        cout<<endl;
        const int days = daysInMonth(i,leap);
        cout<<string(3*day,' ');
        for(int i=1;i<=days;++i){
            cout<<setw(3)<<i;
            if(++day%7==0&&i!=days) cout<<endl;
            day%=7;
        }
    }
}

int main() {
    int year{2021};
    calendar(year);
    return 0;
}