#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<string.h>
#include<cstring> //header files usefull to data opeartios
using namespace std; //std files
class calendar
{
private:
int M; //month
int Y; //year
int FD; //Firstday
public:
calendar(int =03 ,int=2016);
void SFD(); //setfirstday
void print();
};
calendar::calendar(int _M,int _Y)
{
M= _M;
Y= _Y;
}
void calendar::SFD()
{
int D =1; //DAY
int y =Y -(14-M)/12;
int m =M+12*((14-M)/12)-2;
FD = (D+y+y/4/100+y/400+(31*m/12))%7; //DAYS....
}
void calendar::print()
{
int NODIM; //Noofdaysinmonth.
int FDOM=0; //firstdayofmonth
int DOWC=0; //dayofweekcounter
int DC=1; //datecounter
cout<<"\nEnter month that you have on screen.";
cin>>M;
cout<<"\nEnter the year:";
cin>>Y;
switch(M) //M=MONTH
{
case 1:
cout<<setw(21)<<" January "<<Y;
NODIM=31;
break;
case 2:
cout<<setw (21) <<" February "<<Y;
if(Y % 400 == 0 || ( Y % 4 == 0 && Y % 100 != 0))
{
NODIM=29;
}
else
{
NODIM=28;
}
break;
case 3:
cout<<setw(21)<<" March "<<Y;
NODIM=31;
break;
case 4:
cout<<setw(21)<<" April "<<Y;
NODIM=30;
break;
case 5:
cout<<setw(21)<<" May "<<Y;
NODIM=31;
break;
case 6:
cout<<setw(21)<<" June "<<Y;
NODIM=30;
break;
case 7:
cout<<setw(21)<<" July "<<Y;
NODIM=31;
break;
case 8:
cout<<setw(21)<<" August "<<Y;
NODIM=30;
break;
case 9:
cout<<setw(21)<<" Saptebar "<<Y;
NODIM=31;
break;
case 10:
cout<<setw(21)<<" Octobar "<<Y;
NODIM=30;
break;
case 11:
cout<<setw(21)<<" November "<<Y;
NODIM=31;
break;
case 12:
cout<<setw(21)<<" Decembar "<<Y;
NODIM=30;
break;
}
//display the days at the top of each M
cout<<"\n SUN MON TUE WED THU FRI SAT";
cout<<"\n\n"<<setw(2);
//determine where the firdst D begins.
for(FDOM;FDOM<FD;++FDOM)
{
cout<<setw(14);
}
int TFD=FD; //tempfirstday
DC=1;
DOWC=TFD;
//this loop represents the date display and continue to until.
//the number of days in thet M have been reached.
for(DC;DC<=NODIM;++DC)
{
cout<<DC<<setw(6);
++DOWC;
if(DOWC>6)
{
cout<<"\n\n"<<setw(2);
DOWC=0;
}
}
cout<<"\n";
TFD=DOWC+1;
}
int main() //main function
{
calendar c;
c.SFD(); //setfirstday
c.print();
return 0;
}
No comments:
Post a Comment