Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program to find the day of a week of a given date from 15 october 1582 to end of universe using arrays

Posted By: Easy Tutor     Category: C++ Programming     Views: 6572

A C++ Program to find the day of a week of a given date from 15 october 1582 to end of universe using arrays.

Code for Program to find the day of a week of a given date from 15 october 1582 to end of universe using arrays in C++ Programming

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


 int year_code(int,int);

 /*************************************************************************//*************************************************************************///-----------------------------  Main( )  -------------------------------///*************************************************************************//*************************************************************************/

 main()
    {
       clrscr();

       int date;
       int year;
       int month;
       int birth_week;
       int century;
       int birth_year;
       int century_remainder;
       int century_code;
       int birth_year_code;
       int day;

       cout<<"\n Enter the date in the following pattern :"<<endl;
       gotoxy(34,3);
       cout<<"Date - Month - Year"<<endl;

       gotoxy(39,4);
       cout<<"-       -       "<<endl;

       gotoxy(35,4);
       cin>>date;

       gotoxy(43,4);
       cin>>month;

       gotoxy(50,4);
       cin>>year;

       century=year/100;
       birth_year=year%100;

       century_remainder=century%4;

       if(century_remainder==0)
      century_code=date-1;

       elseif(century_remainder==1)
      century_code=date-3;

       elseif(century_remainder==2)
      century_code=date-5;

       else
      century_code=date;

       birth_year_code=year_code(birth_year,month);
       birth_week=century_code+birth_year_code;

       cout<<"\n The day on the given date is : ";

       day=birth_week%7;

       switch(day)
      {
         case 0: cout<<"Friday";
             break;

         case 1: cout<<"Saturday";
             break;

         case 2: cout<<"Sunday";
             break;

         case 3: cout<<"Monday";
             break;

         case 4: cout<<"Tuesday";
             break;

         case 5: cout<<"Wednesday";
             break;

         case 6: cout<<"Thursday";
             break;
      }

       getch();
       return 0;
    }

 /*************************************************************************//*************************************************************************///------------------------  Function Definitions  -----------------------///*************************************************************************//*************************************************************************//*************************************************************************///-------------------------  year_code(int,int)  ------------------------///*************************************************************************/int year_code(int year,int month)
    {
       int code;

       int array_1[12]={3,6,6,2,4,7,2,5,1,3,6,1};
       int array_2[12]={4,7,7,3,5,1,3,6,2,4,7,2};
       int array_3[12]={5,1,1,4,6,2,4,7,3,5,1,3};
       int array_4[12]={6,2,3,6,1,4,6,2,5,7,3,5};
       int array_5[12]={1,4,4,7,2,5,7,3,6,1,4,6};
       int array_6[12]={2,5,5,1,3,6,1,4,7,2,5,7};
       int array_7[12]={3,6,6,2,4,7,2,5,1,3,6,1};
       int array_8[12]={4,7,1,4,6,2,4,7,3,5,1,3};
       int array_9[12]={6,2,2,5,7,3,5,1,4,6,2,4};
       int array_10[12]={7,3,3,6,1,4,6,2,5,7,3,5};
       int array_11[12]={2,3,1,2,4,7,2,5,1,3,6,1};
       int array_12[12]={7,3,4,7,2,5,7,3,6,1,4,6};
       int array_13[12]={5,1,2,5,7,3,5,1,4,6,2,4};
       int array_14[12]={3,6,7,3,5,1,3,6,2,4,7,2};
       int array_15[12]={1,4,5,1,3,6,1,4,7,2,5,7};

       if(year==1 || year==29 || year== 57 || year==85 || year==7 ||
     year==35 || year==63 || year==91 || year==18 || year==46 || year==74)
      code=array_1[month-1];

       elseif(year==2 || year==30 || year== 58 || year==86 || year==13 ||
     year==41 || year==69 || year==97 || year==19 || year==47 || year==75)
      code=array_2[month-1];

       elseif(year==3 || year==31 || year== 59 || year==87 || year==14 ||
     year==42 || year==70 || year==98 || year==25 || year==53 || year==81)
      code=array_3[month-1];

       elseif(year==4 || year==32 || year== 60 || year==88)
      code=array_4[month-12];

       elseif(year==5 || year==33 || year== 61 || year==89 || year==11 ||
     year==39 || year==67 || year==95 || year==22 || year==50 || year==78)
      code=array_5[month-1];

       elseif(year==6 || year==34 || year== 62 || year==90 || year==17 ||
             year==45 || year==73 || year==23 || year==51 || year==79)
      code=array_6[month-1];

       elseif(year==7 || year==35 || year== 63 || year==91)
      code=array_7[month-1];

       elseif(year==8 || year==36 || year==64 || year==92)
      code=array_8[month-1];

       elseif(year==9 || year==37 || year== 65 || year==93 || year==15 ||
     year==43 || year==71 || year==99 || year==26 || year==54 || year==82)
      code=array_9[month-1];

       elseif(year==10 || year==38 || year==66 || year==94 || year==21 ||
             year==49 || year==77 || year==27 || year==55 || year==83)
      code=array_10[month-1];

       elseif(year==12 || year==40 || year==68 || year==96)
      code=array_11[month-1];

       elseif(year==16 || year==44 || year==72 || year==100)
      code=array_12[month-1];

       elseif(year==20 || year==48 || year==76)
      code=array_13[month-1];

       elseif(year==24 || year==52 || year==80)
      code=array_14[month-1];

       elseif(year==28 || year==56 || year==84)
      code=array_15[month-1];

       return code;
    }
  
Share: 



Easy Tutor
Easy Tutor author of Program to find the day of a week of a given date from 15 october 1582 to end of universe using arrays is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!