Wednesday 9 January 2013

Let Us C chapter 2 problem No: C-d


//Calendar Program - Detecting the day on 1st Jan between 1900-xxxx

#include<iostream>


using namespace std;

class calendar
{
    int y,year, days, week, leap, rem;
public:
    void in()
     {
         cout<<"Enter the year:  ";
         cin>>y;
     }

     void diff()
     {
        year = y-1900;
        leap = year/4;
        days = (year*365)+leap;
        week = days%7;
        if(y==2000)
        week=week-1;
        day_checker(week);
     }

     void day_checker(int a)
      {
          if(a==0)
            cout<<"The day on 1st January of "<<y<<" is Monday";
          if(a==1)
            cout<<"The day on 1st January of "<<y<<" is Tuesday";
          if(a==2)
            cout<<"The day on 1st January of "<<y<<" is Wednesday";
          if(a==3)
            cout<<"The day on 1st January of "<<y<<" is Thursday";
          if(a==4)
            cout<<"The day on 1st January of "<<y<<" is Friday";
          if(a==5)
            cout<<"The day on 1st January of "<<y<<" is Saturday";
          if(a==6)
            cout<<"The day on 1st January of "<<y<<" is Sunday";
      }
};

int main(void)
{
  calendar cal;
  cal.in();
  cal.diff();
}


No comments:

Post a Comment

Comments please: