Calender Using C++

Calender project Implementation using c++

#include<iostream>

using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
int main()
{
int d,m,y,mt,dt,yt,k;
char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
cout<<day_name[sum];

}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}




--------------------------------------------------------------------------------------------------------------



#include<iostream>
#include<conio.h>
using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
void print(int date,int day,int year,int month);
int days(int year,int mo)
{
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
months[1] = 29;
return months[mo-1];

}
int main()
{
int d,m,y,mt,dt,yt,k;
char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
//cout<<day_name[sum];
print(d,sum,y,m);
getch();
}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}
void print(int date,int day,int year,int month)
{
int row_find=7,ir=0,p;
int arr[6][7]={0};
while(row_find<date) { row_find+=7; ir++;}
arr[ir][day]=date;
int test=date-1; int testpos=day-1; int c=0;
int irtemp=ir;
while(irtemp>=0)
{
if(testpos>=0){
testpos--;
c++;
} else {testpos=6; irtemp--;}
}
if(c<test) ir++;
cout<<ir<<endl;
p=date+1;
int day_month=days(year,month);
for(int t=day+1;t<7;t++,p++)
arr[ir][t]=p;
for(int i=ir+1;i<5;i++){
for(int j=0;j<7;j++){
arr[i][j]=p;
p++;
if(p>day_month) break;
}
if(p>day_month) break;
}
p=date-1; int k=day-1;
while(ir>=0)
{
if(k>=0){
arr[ir][k]=p;
k--;
}
else {k=6; ir--; p++;}
p--; if(p<=0) break;

}
for(int i=0;i<5;i++)
for(int j=0;j<7;j++)
cout<<arr[i][j]<<"n"[j!=6];
}



---------------------------------------------------------------------------





#include<iostream>
using namespace std;
int leapcheck(int y);
int get(int y,int m,int *);
void print(int date,int day,int year,int month);
void days(int);
int days(int year,int mo)
{
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
months[1] = 29;
return months[mo-1];

}
int main()
{
int d,m,y,mt,dt,yt,k;
// char day_name[7][5]={"sun","mon","tue","wed","thur","fri","sat"};
int month[12]={6,2,2,5,0,3,5,1,4,6,2,4};
int century[4]={0,5,3,1};
cin>>d>>m>>y;
for(int m=1;m<13;m++){
dt=d%7; 
mt=get(y,m,month);
k=y%100;
yt=k%7+k/4+century[((y/100)%4)];
int sum=(yt+mt+dt)%7;
print(d,sum,y,m);
cout<<endl<<endl;
}
return 0;
}
int leapcheck(int year){
if(year%4==0)
if(year%100==0)
if(year%400==0) return 1;
else return 0;
else return 1;
return 0;
}
int get(int y,int m,int *month)
{
int mt;
if(leapcheck(y)==1)
{ if(m==1) mt=5; else if(m==2) mt=1; else mt=month[m-1];}
else
return month[m-1];
return mt;
}
void print(int date,int day,int year,int month)
{
int row_find=7,ir=0,p; int col=5;
int arr[6][7]={0};
while(row_find<date) { row_find+=7; ir++;}
arr[ir][day]=date;
int test=date-1; int testpos=day-1; int c=0;
int irtemp=ir;
while(irtemp>=0)
{
if(testpos>=0){
testpos--;
c++;
} else {testpos=6; irtemp--;}
}
if(c<test) {ir++; col++;}

p=date+1;
int day_month=days(year,month);
for(int t=day+1;t<7;t++,p++)
arr[ir][t]=p;
for(int i=ir+1;i<col;i++){
for(int j=0;j<7;j++){
arr[i][j]=p;
p++;
if(p>day_month) break;
}
if(p>day_month) break;
}
p=date-1; int k=day-1;
while(ir>=0)
{
if(k>=0){
arr[ir][k]=p;
k--;
}
else {k=6; ir--; p++;}
p--; if(p<=0) break;

}
days(month);
cout<<" ";
for(int i=0;i<col;i++)
for(int j=0;j<7;j++){
cout<<arr[i][j]<<"n"[j!=6];
if(arr[i][j]<10&&j!=6) cout<<" ";
else cout<<" ";
}
}
void days(int m)
{
char *s[12]={"---January-------","---February-------","---March-------","---April-------","---May-------","---June-------","---July-------","---August---------","---September--------","---October---------","---November---------","---December--------"};
cout<<s[m-1]<<endl;
cout<<" sun"<<" "<<"m"<<" "<<"tu"<<" "<<"w"<<" "<<" th"<<" "<<"f"<<" "<<" sat"<<endl;


}

No comments:

Post a Comment