Calendar app full project using C++

In this article we will see calendar app full project with its source code. We will make the project using C++ language. We already have given calendar app project by C also. You can use, edit or make your own calendar taking idea from this.

Calendar app full project source code

Now, let’s see source code bellow of calendar app full project using C++. 

// calendar app full project by C++

#include <iostream>
#include <iomanip>
#include <conio.h>
#include <time.h>

using namespace std;

void calendar_app(int year){
	int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};

	int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};    // Days in months

	string list_of_month[] = {"January", "February", "March", "April", "May", "June",
                        "July", "August", "September", "October", "November", "December"};


    cout << "  **************************************" << endl;
    cout << "           Welcome to " << year << endl;
    cout << "  **************************************" << endl << endl;

    int i, days, current, y = year - 1;

    current = (y + y/4 - y/100 + y/400 + t[0] + 1) % 7;

    for(i = 0; i < 12; i++){
    	if(i == 1)
			if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
				days = 29;
			else
				days = month_days[i];
		else
			days = month_days[i];

  		cout << endl << "  *************" << list_of_month[i] << "***************" << endl;

        cout << "  Sun  Mon  Tue  Wed  Thu  Fri  Sat" << endl;

        int k;
        for (k = 0; k < current; k++){
            cout << "     ";
        }

        for (int j = 1; j <= days; j++){
        	k++;
            cout << setw(5) << j;

            if (k > 6){
                k = 0;
                cout << endl;
            }
        }

		if (k)
			cout << endl;

        current = k;
    }

    return;
}

int main(){
	system("cls");

 	time_t ttime = time(0);
	tm *local_time = localtime(&ttime);    // get local time

	int year = 1900 + local_time -> tm_year;
	char option;

	do{
		system("cls");
		calendar_app(year);

		cout << endl << endl;
		cout << "Want to see more? " << endl;
		cout << " - press n for next year " << endl;
		cout << " - press p for previous year " << endl;
		cout << " - press e for exit " << endl;

		option = getche();

		switch(option){
			case 'n':
				year++;
				break;
			case 'p':
				year--;
				break;
		}

	}while(option != 'e' && option != 'E');

    return 0;
}

Output of this calendar app full project

After compiling and running of this calendar app full project code, you will see the calendar of current year. You can see calendar of other year too. Let’s see the output.

  **************************************
           Welcome to 2021
  **************************************


  *************January***************
  Sun  Mon  Tue  Wed  Thu  Fri  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  Mon  Tue  Wed  Thu  Fri  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

  *************March***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************April***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************May***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************June***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************July***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************August***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************September***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************October***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************November***************
  Sun  Mon  Tue  Wed  Thu  Fri  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

  *************December***************
  Sun  Mon  Tue  Wed  Thu  Fri  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


Want to see more?
 - press n for next year
 - press p for previous year
 - press e for exit

Go to previous or next year by pressing ‘p’ or ‘n’ of your app.