Calculating Julian Day Number (JDN) using C++

what is Julian Day Number

Julian Day is the continuous number of days since the beginning of the Julian period and is mainly used by astronomers and in software to easily calculate past days between two events (eg, food production date and sales by date).
JDN_Logo


Code

#include<iostream>
#include <limits>
using namespace std;

void input_data(int &month, int &year, int &day,int &bmonth, int &byear, int &bday);
void calculations(int month, int year, int day, int &jdn);
void output_results(int &month, int &year, int &day, int &jdn,int d);
void calculate_dow(int &jdn , int &dow);
void calculate_difference_and_print(int jdn , int bjdn);

void pause();

int main()
{
int bday;
int bmonth;
int byear;
int bjdn;
int day;
int month;
int year;
int jdn;
int dow;
int bdow;

input_data(month, year, day,bmonth, byear, bday);
// calculate JDN for the present day
calculations(month, year, day, jdn);
// calculate JDN for the Date of birth
calculations(bmonth, byear, bday, bjdn);
calculate_dow(jdn,dow);
calculate_dow(bjdn,bdow);
cout << endl;
output_results(month, year, day, jdn,dow);
output_results(bmonth, byear, bday, bjdn,bdow);
calculate_difference_and_print(jdn,bjdn);
pause();
}


void pause();

// this module is changed to increase the functionality
void input_data (int &month, int &year, int &day,int &bmonth, int &byear, int &bday)
{
std::cout << "enter a month(jan = 1, feb = 2, etc.) : ";
std::cin >> month;
std::cout << "enter a day number(1..31) : ";
std::cin >> day;
std::cout << "enter a year using four digits : ";
std::cin >> year;
std::cout << "enter a month of your DOB(jan = 1, feb = 2, etc.) : ";
std::cin >> bmonth;
std::cout << "enter a day number of your DOB(1..31) : ";
std::cin >> bday;
std::cout << "enter a year using four digits of your DOB : ";
std::cin >> byear;
}

void calculations(int month, int year, int day, int &jdn)
{
int a, m, y, leap_days;
a = (14 - month) / 12;
m = (month - 3) + (12 * a);
y = year + 4800 - a;
leap_days = (y / 4) - (y / 100) + (y / 400);
jdn = day + (((153 * m) + 2) / 5) + (365 * y) + leap_days - 32045;
}

// this module is changed to increase the functionality
void output_results(int &month, int &year, int &day, int &jdn,int d)
{
std::cout << " The JDN for " << month << "/" << day << "/" << year << " is " << jdn << " And Day of Week is " << d << std::endl;
}

void calculate_dow(int &jdn , int &dow){
dow = ((jdn + 1) % 7 );
}

void calculate_difference_and_print(int jdn , int bjdn){
cout << "Diffrence between two JDNs is " << jdn - bjdn << " Days and you are also exact same days old" << endl;
}

void pause()

{
std::cin.clear();
std::cin.ignore(std::numeric_limits<int>::max(), '\n');
std::cout << std::endl;
std::cout << "Press the enter key to continue . . .";
std::cin.get();
}


Output for this program is

Output_JDN
Output


Thanks for being here.
Any comment or suggestion please comment below.

Comments

Popular posts from this blog

C/C++ program to check the Palindrome string.

Second Equation of motion, How to implement using C language

Third Equation of motion, How to implement using C language