this question want the calender,with a number of week and days.
in germany,the 1st week is started with monday.i have a problem with the year 2000 and the month is in january.when i type it, it
shows the 1st week is in 10th.january 2000,
it should be on 3rd january 2000.
some of the years have 53 weeks per year and some year have 52 weeks only. so there is a problem when it has only 53weeks..
i already try to find the error,but i can't find it.i'm using dev c++..
thank you for your help..
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
bool valid(int year, int month2);
bool leapyear(int year);
bool func_wdays(int n);
bool calendardarst(int week, int weekday, int weeknum,int month2);
int first_day(int year);
int daysvmonth2(int year, int month2);
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
int day=0, year=0, month2=0;
int fisrtday, wday, wanz, vmt, week, wende;
cout<<"This program calculates the weeknday, the first days in the year, the weeknday in the month2 of the yeares, the week, with which the month2 starts\n"
<<"The week with that of the month2 finishes and the number of the weekn in the month2.\n"
<<"please, they give the year and the month2 one, in which the above-mentioned data should be shown,\n"
<<"finally the calender will come out with month and days\n"
<<"\nplease give a year : ";
cin>>year;
cout<<"please give a month: ";
cin>>month2;
if(valid(year, month2)){
fisrtday=first_day(year);
cout<<"that date is valid\n"
<<"the fisrt day of a year "<<year<<"is a: ";
func_wdays(fisrtday);
vmt=daysvmonth2(year, month2); //vormonth2s days
week=(vmt+fisrtday)/7+(fisrtday<=3); //die week in der der erste liegt
if(week==0)
{
fisrtday=first_day(year-1);
vmt=daysvmonth2(year-1, 12);
wday=(fisrtday+vmt)%7;
wanz=1+(days[month2]+wday-7)/7+((days[month2]+wday-7)%7>0);
week=(vmt+fisrtday)/7+(fisrtday<=3); //die week in der der erste liegt
week=(wanz-1)+week ;
}
cout<<"\n the fisrt day of that month is on: "<<week<<"calendar week"<<endl;
vmt=daysvmonth2(year, month2);
if(month2==1)
wday=first_day(year);
else
wday=(first_day(year)+vmt)%7; //weeknday des month2
cout<<"the fisrt day of that month is: ";
func_wdays(wday);
wanz=1+(days[month2]+wday-7)/7+((days[month2]+wday-7)%7>0); //anzahl der weekn im month2
cout<<"\nthe number of that week is: "<<wanz<<endl;
//soo und weiter geht's :)) investigation der week with the month2 until end
wende=(wanz-1)+week;
cout<<"the week in the month2 end in this week: "<<wende<<endl;
calendardarst(week, wday, wanz, month2);
}
else{
cout<<"das von ihnen eingegebene Datum ist unvalid, das Programm wird nun beendet.\n";
exit(0);
}
cout<<endl;
system("PAUSE");
main ();
}
bool func_wdays(int n){
switch(n){
case 0: cout<<"Mo "; break;
case 1: cout<<"Di"; break;
case 2: cout<<"Mi"; break;
case 3: cout<<"Do"; break;
case 4: cout<<"Fr"; break;
case 5: cout<<"Sa"; break;
case 6: cout<<"So"; break;
}
return true;
}
int daysvmonth2(int year, int month2){
int n=0;
cout<<year<<endl;
if(leapyear(year))
days[2]=29;
else
days[2]=28;
for(int i=1; i<month2; i++){
n+=days[i];
}
cout<<days[2]<<endl;
return n;
}
bool valid(int year,int month2){
if(month2>12||month2<1)
return false;
if(year<1583)
return false;
return true;
}
bool leapyear(int year){
if (year%4==0 && year%100!=0 || year%400==0)
return true;
else
return false;
}
int first_day(int year){
int n=77, month=1, a=0;
int month2=1, day=1;
for(int i=1583; i<year; i++){
if(leapyear(i))
n+=366;
else
n+=365;
a++;
}
for(int i=month;i<=month2-1;i++){
if(i==2){
if(leapyear(year))
days[2]=29;
else
days[2]=28;
}
n+=days[i];
}
n+=day;
n=(4+n)%7;
return(n);
}
bool calendardarst(int week, int weekday, int weeknum,int month2){
int arr[42];
cout<<endl<<endl;
for(int i=0, buff=1; i<42; i++ ){
if(buff<(days[month2]+1)&&weekday<=i)
{
arr[i]=buff;
buff++;
}
else
arr[i]=0;
}
//ausgabe
cout<<setw(4)<<"Wo |";
for(int i=week, j=week; j<=(weeknum+week-1);j++,i++)
{
cout<<setw(3)<<i;
if(i==52&&i==53)
i=0;
if(i==53)
i=0;
continue;
}
cout<<"\n-----";
for(int i=0;i<weeknum;i++)
cout<<"----";
cout<<"\nMo |";
for(int i=0, j=0, k=1, z=0; i<42; i++){
if(j==6)
{
cout<<endl;
func_wdays(k);
cout<<" |";
k++;
j=0;
z-=41;
}
if(arr[z]==0)
cout<<setw(3)<<" ";
else
cout<<setw(3)<<arr[z];
j++;
z+=7;
}
return true;
}