Name our project ECE246 is Calendar version 1.0. This calendar we make using TURBO C++, this is my project when i study basic programming.
1.Declare the data type and name
#include
void definition();
#define TRUE 1
#define FALSE 0
void main()
{
printf("**********WELCOME**********\n");
printf("************TO*************\n");
printf("********CALENDAR 1.0********\n");
definition();
}
void definition()
{
int year,odd_day,x,y,z,h,month,day;
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
"\n\n\nJanuary",
"\n\n\nFebruary",
"\n\n\nMarch",
"\n\n\nApril",
"\n\n\nMay",
"\n\n\nJune",
"\n\n\nJuly",
"\n\n\nAugust",
"\n\n\nSeptember",
"\n\n\nOctober",
"\n\n\nNovember",
"\n\n\nDecember"
};
2.Mathematic formula
How to Count the Odd Days:
1 ordinary year = 365 days = (52 weeks + 1 day). :. An ordinary year has 1 odd day. ii)1 leap year = 366 days = (52 weeks + 2 days). :. A leap year has 2 odd days. ii)100 years = 76 ordinary years + 24 leap years = [(76 x 52) weeks + 76 days) + [(24 x 52) weeks + 48 days] = 5200 weeks + 124 days = (5217 weeks + 5 days). :. 100 years contain 5 odd days. 200 years contain 10 and therefore 3 odd days. 300 years contain 15 and therefore 1 odd day. 400 years contain (20 + 1) and therefore 0 odd day. Similarly, each one of 800, 1200, 1600, 2000, etc. contains 0 odd days. Remark: (7n + m) odd days, where m < 7 is equivalent to m odd days. Thus, 8 odd days ≡ 1 odd day etc.
Thus with above condition we create a formula to be fit in our program:
x=(year/4-1); y=(year-x); z=2*x + y; odd_day=z%7;
However using the formula we create, there some error when the result is display. As display below for every leap year the first date for the first month is different. This happen because we using for loop to correct the first date of first month of every year.
for ( day = 1; day <= 1 + odd_day * 5; day++ )
{
printf(" ");
}
For full program download HERE