u

Thursday, 5 January 2012

C++ Program displays the month of any year and also has controls to view the previous & the Next months






C++ Program displays the month  of any year and also has controls to view the   previous & the Next  months.

# include <iostream.h>
# include <stdio.h>
# include <conio.h>
void main()
{
    clrscr();
    int b1,b2,o;
     cout<<"  ENTER THE MONTH  : ";
    cin>>b1;
    cout<<"  ENTER THE YEAR  : ";
    cin>>b2;
    a:cout<<"\n";
     o = b1-1;
    int
i,j,k=0,l=0,m=0,n=0,b3,c=0,c1,c2,c3,a[12]={31,28,31,30,31,30,31,31,30
,31,30,31};
    int ab[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    char *z[12] =
{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
char choice;
    for (o=0;o<=11;o++)
    {
     if (b1 == ab[o])
     {
      cout<<"\n         "<<z[o]; cout<<"       "<<b2;
     }
    }
    if(b2%4==0)
        a[1] = 29;
    else
        a[1] = 28;
    if(b2>=2000)
        b3=b2-2000;
    else
    {
        b3=2000-b2;
        b3*=2;
    }
    if(b1==12)
        n=12;
    if(b1==1)
    {
        k=11;
        l=1;
        for(i=0;i<=k;i++)
            m+=a[i];
    }
    for(i=0;i<(b1-1);i++)
        c+=a[i];

       c2=(c+b3)%7;
   textcolor(10);
    cout<<"\n\n\n\n";
    cout<<"  SU  MO  TU  WE  TH  FR  SA\n\n";
    for(j=0;j<c2;j++)
        cout<<"    ";
    for(j=1;j<=a[b1-1];j++)
    {
        if(j<10)
            cout<<"   "<<j;
        else
            cout<<"  "<<j;
        if((j+c2)%7==0)

            cout<<"\n\n";
    }
    cout<<"\n";


    cout<<"\n\n Use these arrow keys to display the Sequential Year or Month :   \n";
    cout<<"**************************************************************\n";
    cout<<" |         Up    = Next Year      |   Down = Previous Year   | \n";
    cout<<" |         Right = Next Month   |   Left = Next Month   | \n";
    cout<<"************************************************************** \n";
    choice = getch();
    if (choice==0)
    {
     choice = getch();
     switch(choice)
     {
      case 80  : {b2-=1; goto a; break;}
      case 72  : {b2+=1;goto a; break;}
      case 75 :  {
          if (b1!=1)
                    b1-=1;
                  else
                   {b1=12; b2-=1;}
                 goto a; break;}
      case 77 : {
                 if (b1!=12)
                   b1+=1;
                 else
                   {b1 = 1; b2+=1;}
                 goto a; break;}
     }
    }
 getch();
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More