Question
Here is the prompt for reference, and to understand my code. I need help with Part 5. Thanks. // HERE IS: julianfuncs.h #ifndef __EE231_julianfuncs_h__ #define
Here is the prompt for reference, and to understand my code. I need help with Part 5. Thanks.
// HERE IS: julianfuncs.h
#ifndef __EE231_julianfuncs_h__
#define __EE231_julianfuncs_h__
void JDNtoYMD(int J, bool julian, int& Y, int& M, int& D);
int GregorianToJDN(int Y, int M, int D);
int JulianToJDN(int Y, int M, int D);
#endif // __EE231_julianfuncs_h__
// HERE IS: julianfuncs.cpp
# include "julianfuncs.h"
int GregorianToJDN(int Y, int M, int D)
{
int jdn;
jdn = (1461 * (Y + 4800 + (M - 14)/12))/4 + (367 *(M - 2 - 12 * ((M - 14)/12)))/12-(3*((Y + 4900 + (M - 14)/12)/100))/4 + D - 32075;
return jdn;
}
int JulianToJDN(int Y,int M, int D)
{
int jdn ;
jdn = 367 * Y - (7 * (Y + 5001 + (M - 9)/7))/4 + (275 * M)/9 + D + 1729777;
return jdn;
}
void JDNtoYMD(int J, bool julian,int &Y, int &M, int &D)
{
int y = 4716, j = 1401, m = 2, n = 12, r = 4, p = 1461, v = 3, u = 5, s = 153, w = 2, B = 274277, C = -38;
int f, e , g , h;
if(julian) f = J + j;
else
{
f = J + j + ( ( ( 4 * J + B ) / 146097 ) * 3 ) / 4 + C;
e = r * f * v;
g = (e % p ) / r;
h = u * g + w;
D = ( ( h % s ) / u ) + 1;
M = ( ( h / s + m ) % n) + 1;
Y = ( e / p ) - y + ( n + m + M ) / n;
}
}
// HERE IS: JulianDate.h
#ifndef __EE231_JulianDate_h__
#define __EE231_JulianDate_h__
#include
class GregorianDate;
class JulianDate
{
private:
int _jdn;
public:
JulianDate();
JulianDate(int JDN);
JulianDate(int year, int month, int day);
JulianDate(const GregorianDate& g);
void set(int JDN);
void set(int Y, int M, int D);
int getJDN() const;
int getYear() const;
int getMonth() const;
int getDay() const;
};
// write data to stream
inline std::ostream& operator
{
return os
}
// number of days between two dates
inline int operator-(const JulianDate& a, const JulianDate& b)
{
int diff = b.getJDN() - a.getJDN();
if( diff
return diff;
}
// date n days after date d
inline JulianDate operator+(const JulianDate& d, int n)
{
JulianDate newJulianDate( d.getJDN() + n );
return newJulianDate;
}
#endif // __EE231_JulianDate_h__
// HERE IS: JulianDate.cpp
# include "julianDate.h"
# include "gregorianDate.h"
JulianDate::JulianDate()
{
_jdn=0;
}
JulianDate::JulianDate(int JDN)
{
_jdn = JDN;
}
JulianDate::JulianDate( int year, int month, int day )
{
_jdn = JulianToJDN( year, month, day);
}
JulianDate::JulianDate(const GregorianDate &g)
{
_jdn = GregorianToJDN( g.getYear(), g.getMonth(), g.getDay() );
}
void JulianDate::set(int JDN)
{
_jdn = JDN;
}
void JulianDate::set( int Y, int M, int D )
{
_jdn = JulianToJDN( Y, M, D );
}
int JulianDate:: getJDN() const
{
return _jdn;
}
int JulianDate::getYear() const
{
int day, month, year;
JDNtoYMD( _jdn, true, year, month, day );
return year;
}
int JulianDate::getMonth() const
{
int day,month,year;
JDNtoYMD( _jdn, true, year, month, day);
return month;
}
int JulianDate::getDay() const
{
int day, month, year;
JDNtoYMD( _jdn, false, year, month, day );
return day;
}
// HERE IS: GregorianDate.h
#ifndef __EE231_GregorianDate_h__
#define __EE231_GregorianDate_h__
#include
class JulianDate;
/* Description:
*
*
*/
class GregorianDate
{
private:
int _year, _month, _day;
public:
GregorianDate();
GregorianDate(int JDN);
GregorianDate(int year, int month, int day);
GregorianDate(const JulianDate& j);
void set(int JDN);
void set(int Y, int M, int D);
int getJDN() const;
int getYear() const;
int getMonth() const;
int getDay() const;
};
// write data to stream
inline std::ostream& operator
{
os
return os;
}
// number of days between two dates
inline int operator-(const GregorianDate& a, const GregorianDate& b)
{
int jdn1 = GregorianToJDN(a.getYear(),a.getMonth(),a.getDay());
int jdn2 = GregorianToJDN(b.getYear(),b.getMonth(),b.getDay());
int diff = jdn2 - jdn1;
if( diff
return diff;
}
// date n days after date d
inline GregorianDate operator+(const GregorianDate& d, int n)
{
GregorianDate newDate(d.getJDN()+n);
return newDate;
}
#endif // __EE231_GregorianDate_h__
// HERE IS: GregorianDate.cpp
# include "gregorianDate.h"
# include "julianDate.h"
GregorianDate::GregorianDate()
{
_year = 0;
_month=0;
_day=0;
}
GregorianDate::GregorianDate(int year,int month,int day)
{
_year = year;
_month = month;
_day = day;
}
GregorianDate::GregorianDate(int JDN)
{
JDNtoYMD(JDN,false,_year,_month,_day);
}
GregorianDate::GregorianDate(const JulianDate &j)
{
JDNtoYMD(j.getJDN(),false,_year,_month,_day);
}
void GregorianDate::set(int JDN)
{
JDNtoYMD(JDN,false,_year,_month,_day);
}
void GregorianDate::set(int Y, int M, int D)
{
_year = Y;
_month = M;
_day = D;
}
int GregorianDate::getJDN() const
{
return GregorianToJDN(_year,_month,_day);
}
int GregorianDate:: getYear() const
{
return _year;
}
int GregorianDate::getMonth() const
{
return _month;
}
int GregorianDate::getDay() const
{
return _day;
}
// HERE IS: test-jdate.cpp
#include
#include "JulianDate.h"
#include "GregorianDate.h"
template
void testDate(T& today, T& td)
{
int diff = today-td;
std::cout
std::cout
std::cout
std::cout
std::cout
}
// returns current Julian Day Number
double NowAsJDN()
{
time_t t = time(0);
return (t / 86400.0) + 2440587.5;
}
int
main()
{
std::cout
std::cout
std::cout
// If doing the extra credit part,
// add to and modify this section to test the classes
// GregorianDate2 and JulianDate2
// BEGIN
JulianDate jtoday(NowAsJDN()), jtd(1970,8,1);
std::cout
testDate(jtoday, jtd);
std::cout
GregorianDate gtoday(NowAsJDN()), gtd(1970,8,1);
std::cout
testDate(gtoday, gtd);
std::cout
// END
return 0;
}
Part 1: Julian Day Number Calculations The calculations required for our two classes are described in the Wikipedia article on Julian day available at h an day. The three functions we need are described in sections 4.1, 4.2, and 4.5. The function prototypes for these functions should be placed into a header file called julianfuncs.h and implemented in the file julianfuncs.cpp. The .h file will be provided for you so you must implement these three functions in the .cpp file. Part 1: Julian Day Number Calculations The calculations required for our two classes are described in the Wikipedia article on Julian day available at h an day. The three functions we need are described in sections 4.1, 4.2, and 4.5. The function prototypes for these functions should be placed into a header file called julianfuncs.h and implemented in the file julianfuncs.cpp. The .h file will be provided for you so you must implement these three functions in the .cpp file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started