- #1
FRANCLI
- 12
- 0
Hello...
the is my code:
#include<iostream.h>
#include<iomanip.h>
void show(int m, int w, int n)
{
cout<<endl<<"Sun Mon Tue Wed Thu Fri Sat\n";
cout<<setw((w*5)+1);
for(int r=1;r<=(7-w);r++) cout<<r<<" ";
int count=0;
cout<<endl;
for (;r<=n;r++)
{
if(r<10)
{
cout<<r<<" ";
count++;
}
else
{
cout<<r<<" ";
count++;
}
if((count%7)==0)
cout<<endl;
}
}
void print(int v, int q,int y)
{
int nd;
switch (v)
{
case 1 :
nd=31;
cout<<"\n\n\nJan\n";
show(v,q,nd);
break;
case 2:
if(y%4==0)
nd=29;
else
nd=28;
cout<<"\n\n\nFeb\n";
show(v,q,nd);
break;
case 3 :
nd=31;
cout<<"\n\n\nMar\n";
show(v,q,nd);
break;
case 4:
nd=30;
cout<<"\n\n\nApr\n";
show(v,q,nd);
break;
case 5 :
nd=31;
cout<<"\n\n\nMay\n"; show(v,q,nd);
break;
case 6:
nd=30;
cout<<"\n\n\nJun\n";
show(v,q,nd);
break;
case 7 :
nd=31;
cout<<"\n\n\nJul\n";
show(v,q,nd);
break;
case 8 :
nd=31;
cout<<"\n\n\nAug\n";
show(v,q,nd);
break;
case 9 :
nd=30;
cout<<"\n\n\nSep\n";
show(v,q,nd);
break;
case 10 :
nd=31;
cout<<"\n\n\nOct\n";
show(v,q,nd);
break;
case 11:
nd=30;
cout<<"\n\n\nNov\n";
show(v,q,nd);
break;
case 12:
nd=31;
cout<<"\n\n\nDec\n";
show(v,q,nd);
break;
}
}
int main()
{ int x;
int year;
cout<<" Welcome \n *******"<<endl<<"enter the year";
cin>>year;
int a= (int)(year/100);
int b= a*100 ;
int c= (year-b);
int d;
if((b>=1700&&b<=1799)||(b>=2100&&b<=2199)||(b>=2500&&b<=2599))
d=4;
else if((b>=1800&&b<=1899)||(b>=2200&&b<=2299)||(b>=2600&&b<=2699))
d=2;
else if((b>=1900&&b<=1999)||(b>=2300&&b<=2399))
d=0;
else if((b>=2000&&b>=2099)||(b>=2400&&b<=2499))
d=6;
int e=(int)(c/4);
for(int i=1;i<=12;i++)
{
switch(i)
{
case 10:
x=0;
break; case 1: if((year%4)==0) x=6; else x=0; break; case 2: if((year%4)==0) x=2;else x=3; break;
case 3 : case 11:
x=3;
break;
case 4: case 7:
x=6;
break;
case 5 :
x=1;
break;
case 6 :
x=4; break;
case 8 :
x=2; break;
case 12 : case 9 :
x =5;
break;}
int z;
z=((c+d+e+x+1)%7);
print(i,z,year); //(Still Julian Calendar in Great Britain)
}
cout<<"\n\n PleAsE GrAde uS weLL "<<endl<<" ***********";
return 0;
}
I have written a code but there is a problem in this code .
The code gives a true calendar until 1999 but when it comes to the year 2000 the first day of the year is saturday but my code gives that the first day of the year is sunday ,, and so on for the other years that follows this year and I don't know really what is the problem.
First I use Julian method to calculate the first day of the week ,and here is an example to illustrate this method.
January 1, 2000
Look up the 2000s in the centuries table: 6
This is the table :
1700–1799 4 (Still Julian Calendar in Great Britain and its colonies until 1752)
1800–1899 2
1900–1999 0
2000–2099 6
2100–2199 4
2200–2299 2
2300–2399 0
2400–2499 6
2500–2599 4
2600–2699 2
Note the last two digits of the year: 00
Divide the 00 by 4: 0/4 = 0 and drop the fractional part: 0
Look up January in the months table: 6 (leap)
This is the table:
January 0 (in leap year 6)
February 3 (in leap year 2)
March 3
April 6
May 1
June 4
July 6
August 2
September 5
October 0
November 3
December 5
Add all numbers from steps 1–4 to the day of the month (in this case, 19): 1+6+00+0+6=13.
Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
Find the remainder in the days table: 6=Saturday.
This is the table:
Sunday 0
Monday 1
Tuesday 2
Wednesday 3
Thursday 4
Friday 5
Saturday 6
the is my code:
#include<iostream.h>
#include<iomanip.h>
void show(int m, int w, int n)
{
cout<<endl<<"Sun Mon Tue Wed Thu Fri Sat\n";
cout<<setw((w*5)+1);
for(int r=1;r<=(7-w);r++) cout<<r<<" ";
int count=0;
cout<<endl;
for (;r<=n;r++)
{
if(r<10)
{
cout<<r<<" ";
count++;
}
else
{
cout<<r<<" ";
count++;
}
if((count%7)==0)
cout<<endl;
}
}
void print(int v, int q,int y)
{
int nd;
switch (v)
{
case 1 :
nd=31;
cout<<"\n\n\nJan\n";
show(v,q,nd);
break;
case 2:
if(y%4==0)
nd=29;
else
nd=28;
cout<<"\n\n\nFeb\n";
show(v,q,nd);
break;
case 3 :
nd=31;
cout<<"\n\n\nMar\n";
show(v,q,nd);
break;
case 4:
nd=30;
cout<<"\n\n\nApr\n";
show(v,q,nd);
break;
case 5 :
nd=31;
cout<<"\n\n\nMay\n"; show(v,q,nd);
break;
case 6:
nd=30;
cout<<"\n\n\nJun\n";
show(v,q,nd);
break;
case 7 :
nd=31;
cout<<"\n\n\nJul\n";
show(v,q,nd);
break;
case 8 :
nd=31;
cout<<"\n\n\nAug\n";
show(v,q,nd);
break;
case 9 :
nd=30;
cout<<"\n\n\nSep\n";
show(v,q,nd);
break;
case 10 :
nd=31;
cout<<"\n\n\nOct\n";
show(v,q,nd);
break;
case 11:
nd=30;
cout<<"\n\n\nNov\n";
show(v,q,nd);
break;
case 12:
nd=31;
cout<<"\n\n\nDec\n";
show(v,q,nd);
break;
}
}
int main()
{ int x;
int year;
cout<<" Welcome \n *******"<<endl<<"enter the year";
cin>>year;
int a= (int)(year/100);
int b= a*100 ;
int c= (year-b);
int d;
if((b>=1700&&b<=1799)||(b>=2100&&b<=2199)||(b>=2500&&b<=2599))
d=4;
else if((b>=1800&&b<=1899)||(b>=2200&&b<=2299)||(b>=2600&&b<=2699))
d=2;
else if((b>=1900&&b<=1999)||(b>=2300&&b<=2399))
d=0;
else if((b>=2000&&b>=2099)||(b>=2400&&b<=2499))
d=6;
int e=(int)(c/4);
for(int i=1;i<=12;i++)
{
switch(i)
{
case 10:
x=0;
break; case 1: if((year%4)==0) x=6; else x=0; break; case 2: if((year%4)==0) x=2;else x=3; break;
case 3 : case 11:
x=3;
break;
case 4: case 7:
x=6;
break;
case 5 :
x=1;
break;
case 6 :
x=4; break;
case 8 :
x=2; break;
case 12 : case 9 :
x =5;
break;}
int z;
z=((c+d+e+x+1)%7);
print(i,z,year); //(Still Julian Calendar in Great Britain)
}
cout<<"\n\n PleAsE GrAde uS weLL "<<endl<<" ***********";
return 0;
}
I have written a code but there is a problem in this code .
The code gives a true calendar until 1999 but when it comes to the year 2000 the first day of the year is saturday but my code gives that the first day of the year is sunday ,, and so on for the other years that follows this year and I don't know really what is the problem.
First I use Julian method to calculate the first day of the week ,and here is an example to illustrate this method.
January 1, 2000
Look up the 2000s in the centuries table: 6
This is the table :
1700–1799 4 (Still Julian Calendar in Great Britain and its colonies until 1752)
1800–1899 2
1900–1999 0
2000–2099 6
2100–2199 4
2200–2299 2
2300–2399 0
2400–2499 6
2500–2599 4
2600–2699 2
Note the last two digits of the year: 00
Divide the 00 by 4: 0/4 = 0 and drop the fractional part: 0
Look up January in the months table: 6 (leap)
This is the table:
January 0 (in leap year 6)
February 3 (in leap year 2)
March 3
April 6
May 1
June 4
July 6
August 2
September 5
October 0
November 3
December 5
Add all numbers from steps 1–4 to the day of the month (in this case, 19): 1+6+00+0+6=13.
Divide the sum from step 5 by 7 and find the remainder: 13/7=1 remainder 6
Find the remainder in the days table: 6=Saturday.
This is the table:
Sunday 0
Monday 1
Tuesday 2
Wednesday 3
Thursday 4
Friday 5
Saturday 6