A program to get two dates entered by the user, using a class date, with the following member functions:
1. getdata()- intakes date entered by the user
2. display()- displays date
3. addit()- adds the 2 date entered by the user

 

#include<iostream.h>
#include<conio.h>


class date
{
private:
int day;
int month;
int year;

public:
void getdata()
{
cin>>day;
cout<<"/";
cin>>month;
cout<<"/";
cin>>year;
}

void display()
{
cout<<"The date is "<<day<<"/"<<month<<"/"<<year<<endl;
}

void addit(date aa, date bb)
{
day=aa.day+bb.day;
month=aa.month+bb.month;
year=aa.year+bb.year;
while(day>30)
{
day-=30;
month++;
}
while(month>12)
{
month-=12;
year++;
}
}
}date1,date2,date3;


void main()
{
clrscr();

cout<<"Enter the first date (dd/mm/yy): ";
date1.getdata();

cout<<"Enter the second date (dd/mm/yy):";
date2.getdata();

date3.addit(date1, date2);
date3.display();

gotoxy(25,24); cout<<"Press any key to continue......";
getch();
}

 

< Back