You are on page 1of 2

#include <cstdlib>

#include <iostream>
using namespace std;
struct Mytime
{
int hours;
int mins;
};

struct Mydate
{
int day;
int month;
int year;
};

int main(int argc, char *argv[])


{
int th,tm;
struct Mytime time;
cout<<"Please enter departure time: \n";
cin>>time.hours>>time.mins;

struct Mytime duration;


cout<<"Please enter duration of journey:";
cin>>duration.hours>>duration.mins;
struct Mytime arrive;
th = duration.hours + time.hours;
tm = duration.mins + time.mins;
if(tm > 60 || arrive.hours > 24)
{
arrive.mins= tm%60;
arrive.hours= th + tm/60;
arrive.hours= arrive.hours%24;
}
cout<<"The arival time is "<< arrive.hours<<":"<<arrive.mins<< "\n";
struct Mydate departure;
struct Mydate arrival;

cout<<"Enter Departure Date:";


cin>>departure.day>>departure.month>>departure.year;
cout<<"Departure Date is: " <<departure.day<<"."<<departure.month<<"."<<depa
rture.year<<endl;
int total = duration.hours + time.hours;
if((total>24)&&(departure.day==28) && (departure.month == 2))
{
arrival.day = ((departure.day + 1)-28);
arrival.month= (departure.month+1);
cout<<"Arrival Date is : "<<endl;
cout<<arrival.day<<"."<<arrival.month<<"."<<departure.year<<endl;
}
else if((total>24)&& (departure.day==30) && ((departure.month == 4) || (depa
rture.month == 6) || (departure.month == 9) || (departure.month == 11)))
{
arrival.day=((departure.day+1)- 30);
arrival.month= (departure.month+1);
cout<<"Arrival Date is : "<<endl;
cout<<arrival.day<<"."<< arrival.month<<"."<<departure.year<<endl;
}
else if((total>24) && (departure.day==31) &&((departure.month == 1) || (depa
rture.month == 3) || (departure.month== 5) || (departure.month == 7) || (departu
re.month == 8) || (departure.month == 10)))
{
arrival.day = ((departure.day+1)-31);
arrival.month= (departure.month+1);
cout<<"Arrival Date is : "<<endl;
cout<< arrival.day<<"."<< arrival.month<<"."<<departure.year<<endl;
}
else if((total>24) && (departure.day==31) && (departure.month == 12))
{
arrival.day = ((departure.day+1) -31);
arrival.month = ((departure.month+1)-12);
arrival.year = (departure.year+1);
cout<<"Arrival Date is : " <<"";
cout<<arrival.day<<"." <<arrival.month<<"."<<arrival.year<<endl;
}
else if(total>24)
{ arrival.day=(departure.day+1);
cout<< "Arrival Date is:"<<arrival.day<<"." <<departure.month<<"."<<de
parture.year<<endl;
}

system("PAUSE");
return EXIT_SUCCESS;
}

________________________________________________________________________________
________
Leap year:
if((total>24) && (departure.day == 29) && (departure.month == 2) && ((departure
.year%4)==0)&&(((departure.year%100!=0)||(departure.year % 400 ==0))))
{
arrival.day=((departure.day + 1)-29);
arrival.month=((departure.month +1));
cout<<arrival.day<<"."<<arrival.month<<"."<<departure.year<<e
ndl;
}