#include<iostream.h>
#include<conio.h>
class Date
{
public:
int d1,d2,m1,m2,y1,y2;
int d,m,y;
void insert()
{
cout<<"Enter the first date in dd/mm/yy format"<<endl;
cin>>d1>>m1>>y1;
if(d1>30 || m1>12)
cout<<"Please enter a valid input"<<endl;
cout<<"Enter the second date in dd/mm/yy format"<<endl;
cin>>d2>>m2>>y2;
if(d2>30 || m2>12)
cout<<"Please enter a valid input"<<endl;
}
void calculate()
{
if(d1>d2)
{
d=(d2+30)-d1;
m1=m1+1;
}
else
d=d2-d1;
if(m1>m2)
{
m=(m2+12)-m1;
y1=y1+1;
}
else
m=m2-m1;
y=y2-y1;
}
void show()
{
cout<<"Difference between:"<<endl;
cout<<d1<<"/"<<m1<<"/"<<y1<<"and"<<d2<<"/"<<m2<<"/"<<y2<<endl;
cout<<y<<"year"<<'\t'<<m<<"month"<<'\t'<<d<<"day";
}
};
void main()
{
Date ob;
clrscr();
ob.insert();
ob.calculate();
ob.show();
getch();
}
OUTPUT
#include<conio.h>
class Date
{
public:
int d1,d2,m1,m2,y1,y2;
int d,m,y;
void insert()
{
cout<<"Enter the first date in dd/mm/yy format"<<endl;
cin>>d1>>m1>>y1;
if(d1>30 || m1>12)
cout<<"Please enter a valid input"<<endl;
cout<<"Enter the second date in dd/mm/yy format"<<endl;
cin>>d2>>m2>>y2;
if(d2>30 || m2>12)
cout<<"Please enter a valid input"<<endl;
}
void calculate()
{
if(d1>d2)
{
d=(d2+30)-d1;
m1=m1+1;
}
else
d=d2-d1;
if(m1>m2)
{
m=(m2+12)-m1;
y1=y1+1;
}
else
m=m2-m1;
y=y2-y1;
}
void show()
{
cout<<"Difference between:"<<endl;
cout<<d1<<"/"<<m1<<"/"<<y1<<"and"<<d2<<"/"<<m2<<"/"<<y2<<endl;
cout<<y<<"year"<<'\t'<<m<<"month"<<'\t'<<d<<"day";
}
};
void main()
{
Date ob;
clrscr();
ob.insert();
ob.calculate();
ob.show();
getch();
}
OUTPUT
No comments:
Post a Comment