The class should be capable of storing, manipulating and printing dates. Dates can be initialized by assigning 3 numbers - the day, the month and the year (initially restricted to any date after 1st January 1900 and before the year 3000)

e.g. Date d1(26,3,1999);

Dates will be printed by either of two member functions:

d1.print_nz();  // outputs 26/03/1999
d1.print_text();    // outputs Friday, 26th March 1999

or by the overloaded << operator:

cout << d1;       // outputs Friday, 26th March 1999

Dates can be manipulated by adding a number of days (from 0 to 999,999) - either by calling a function:

d1.add(1234);

or by using the overloaded + operator:

d2 = d1 + 1234;

#include <iostream.h>                    |   #include <iostream.h>
#include "a3.h"                     |   #include "a3.h"
using namespace B;              |   using namespace B;
                        |
int main() {                    |   int main() {
   Date d1(26,3,1999),d2;           |      Date d1(1,1,2000);
                        |
   d1.print_nz();               |      d1.print_nz();
   cout << endl;              |      cout << endl;
   d2 = d1 + 6;                     |      d1.add(999999);
   cout << d2 << endl;                  |           d1.print_text();
}                       |      cout << endl;
                        |   }

produces as output:

26/03/1999                  |   01/01/2000
Thursday, 1st April 1999            |   Saturday, 27th November 4737

There are 365 days in a year, except for leap years, when there are 366. Leap years are all divisible by 4 and not 100, except that those divisible by 400 are leap years. So 2100 and 2200 are not leap years, 2000 2004 2008 2400 are leap years.

Zeller’s Congruence is a method for finding the day of the week of any given date. If a date is given in the form dd mm yyyy, then the day of the week d can be calculated using the following algorithm (a,b,c,d and m are all integers):

if mm is January or February then first subtract 1 from yyyy

a = the truncated value of (2.6m - 0.2)
b = remainder when yyyy is divided by 100
c = yyyy/100

m is related to the month.
For March m has the value 1, April 2 ... December 10, January 11 and February 12.

d is the remainder when a + dd + b + b/4 + c/4 - 2c is divided by 7
if d is less than 0 then add 7 to d

d has the value 0 for Sunday, 1 for Monday, 2 for Tuesday etc.

Edited 3 Years Ago by Nick Evan: Fixed formatting

First, use code tags.

#include <iostream.h> | #include <iostream.h>
#include "a3.h" | #include "a3.h"
using namespace B; | using namespace B;
|
int main() { | int main() {
Date d1(26,3,1999),d2; | Date d1(1,1,2000);
|
d1.print_nz(); | d1.print_nz();
cout << endl; | cout << endl;
d2 = d1 + 6; | d1.add(999999);
cout << d2 << endl; | d1.print_text();
} | cout << endl;
| }

Code tags won't help this mess. If you're going to do a verbatim copy/paste, you need to at least make sure you copy and paste something legible. Get rid of all the | characters, etc.

Why is this a poll? No, what you posted makes no sense. On the other hand, google "Zeller's Congruence" and you'll get all sorts of links, most of which make far more sense than what you posted, possibly because the formulas aren't all screwed up by the copy and paste. Start going through them till it makes sense. This should be a poll of one person: you.

Comments
good comments :)
Sing it brother
#include<iostream.h>
#include<conio.h>
int leapyear(int);
int Month_31(int);

/*      d1.print_nz();   	// outputs 26/03/1999
	d1.print_text();	// outputs Friday, 26th March 1999

	cout << d1;		// outputs Friday, 26th March 1999

Dates can be manipulated by adding a number of days
(from 0 to 999,999) - either by calling a function:

	d1.add(1234);

or by using the overloaded + operator:

	d2 = d1 + 1234;*/

class Date
 {
   int Day,Month,Year;
  public:

  Date()
  {

  }
  int check_days_of();
  void print_nz()        // outputs 26/03/1999
  {
   cout<<Day<<"/"<<Month<<"/"<<Year;
  }                          //end of print_nz
void print_text();    	// outputs Friday, 26th March 1999

void add(long N);
 friend istream& operator>>(istream& cin, Date& D);
 friend void operator<<(ostream& cout, const Date& dt);
  Date(int Day,int Month,int Year)
   {
    this->Day=Day;
    this->Month=Month;
    this->Year=Year;
   }
  void setDate()
   {
    int DayMonth,Year;
    cout<<"\n Enter Day";cin>>Day;
    this->Day=Day;
    cout<<"\nEnter Month";cin>>Month;
    this->Month=Month  ;
    cout<<"\n Enter Year";cin>>Year;
    this->Year=Year;
   }
  void showDate()
   {
    cout<<"\n Day="<<Day<"\t";
    cout<<"\n Month="<<Month<"\t";
    cout<<"\n Year="<<Year<"\t";
   }
 

 } ;//end of Date

		//check_days_of(month)
int Date:: check_days_of()
{
int arr[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if(leapyear(Year))
    return 29;
    else
    return arr[Month-1];
}
		//Add()
 void Date:: add(long N)
 {
   //int d=;
  while(Day+N>this->check_days_of())
  {
     if(Month==12)
     {
      Year++;
      Month=1;
     }
     else Month++;
    if(N>this->check_days_of())
    N=N-this->check_days_of();

  }
       Day+=N;
  }

//end of add()

//Overloading -

void operator<<(ostream& cout, const Date& D)
{
    cout << D.Day << '/' << D.Month << '/' << D.Year;

}
//end of operator << overloading
istream& operator >>(istream& cin, Date& D)
{
 int Da,M,Y;
 cout<<"\n\nEnter DAY";cin>>Da;
 cout<<"\n\nEnter month";cin>>M;
 cout<<"\n\nEnter year";cin>>Y;
 D.Day=Da;D.Month=M;D.Year=Y;
 return cin;

}
end of operator >> overloading::
int Month_31(int M)
 {
  switch(M)
   {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    return 1;
   }
   return 0;

}
  int leapyear(int Y)
   {
    if(Y%4==0)
    return 1;
    else
    return 0;

   }


void Date:: print_text()
  {
int a,b,c ;
int d,g;
int m;
switch(Month)
{
 case 1:
 {
  m=11;
  break;

 }
 case 2:
  {
  m=12;
  break;
  }
  default:
  {
   m=Month-2;
   break;
  }
}
		//method  for finding Day of week
a=((2.6*m)-0.2);
b=Year%100;
c=Year/100;


d=(a+Day+b+b/4+c/4-(2*c));
d=d%7;


if(d<0)
{
 d+=7;
}

int choice;

switch(d)
{

case 0:
cout<<"\n\n\t SUNDAY";
break;

case 1:
cout<<"\n\n\t MONDAY";
break;
case 2:
cout<<"\n\n\t TUESDAY";
break;
case 3:
cout<<"\n\n\t WEDNESDAY";
break;
case 4:
cout<<"\n\n\t THURSDAY";
break;
case 5:
cout<<"\n\n\t FRIDAY";
break;

case 6:
cout<<"\n\n\t SATURDAY";
break;



	  // End of Day of Week /
}

 cout<<Day;
    if(Day%10==1)
    cout<<"st " ;
    else if(Day%10==2)
    cout<<"nd ";
    else if(Day%10==3)
    cout<<"rd ";
     else
     cout<<"th ";
      switch(Month)
    {
    case 1:
    {
    cout<<"January ";
     break;
    }
    case 2:
    {
    cout<<"February ";
     break;
    }case 3 :
    {
    cout<<"March ";
    break;
    }
    case 4 :
    {
    cout<<"April ";
     break;
    }
    case 5:
    {
    cout<<"May ";
     break;
    }
    case 6 :
    {
    cout<<"June ";
     break;
    }
    case 7:
    {
    cout<<"July ";
     break;
    }
    case 8:
    {
     cout<<"August ";
     break;
    }
    case 9:
    {
     cout<<"September " ;
     break;
    }
    case 10:
    {

    cout<<"October ";
     break;
    }
    case 11:
    {
    cout<<"November ";
     break;
    }
    case 12:
    {
     cout<<"December ";
     break;
    }

    }//end of switch;
   cout<<Year;
  }                 //end of print_text






void main()
{
clrscr();

Date Dob,cdate(30,12,2010),Age;

cout<<"\t\t\tThe Current Date Is::"   ;
cout<<"\n\n\t\t\t";
    cdate.print_nz();
    cout<<"\n\n\t\t\t";

cdate.print_text();
  cdate.add(1);

cdate.print_text();
getch();

}

I have came up with this code.
But some errors are there. Do let me know about this :)

>> But some errors are there.

Tell us what they are. Don't make us guess.


Go through them one by one, fix them, recompile. You don't need help on a lot of these. They're obvious and the error messages tell you exactly what's wrong. Just look at them and look at the error messages and fix them (i.e. lines 57 and 113).

The problems here should jump out at you. Pretend you are the compiler and try to figure out what they mean.

cout<<"\n Day="<<Day<"\t";
end of operator >> overloading::
This article has been dead for over six months. Start a new discussion instead.