⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hijrah.cpp

📁 VC+6.0 编写的关于计算穆斯林祷告的程序. 比较使用的应用小程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   {
    mh1=*mh+1;
    yh1=*yh;
    if(mh1>12) {mh1=mh1-12;yh1++;}
    found=BH2GA(yh1,mh1,&yg1,&mg1,&dg1,&dw1);
    if(*dg==dg1) {*yh=yh1;*mh=mh1;*dh=1;}  /* Make sure that the month is 30days if not make adjustment */
   }

   return found;
}
/****************************************************************************/
/* Name:    JDToGCalendar						    */
/* Type:    Procedure                                                       */
/* Purpose: convert Julian Day  to Gdate(year,month,day)                    */
/* Arguments:                                                               */
/* Input:  The Julian Day: JD                                               */
/* Output: Gregorian date: year:yy, month:mm, day:dd                        */
/****************************************************************************/
double JDToGCalendar(double JD, int *yy,int *mm, int *dd)
{
double A, B, F;
int alpha, C, E;
long D, Z;

  Z = (long)floor (JD + 0.5);
  F = (JD + 0.5) - Z;
  alpha = (int)((Z - 1867216.25) / 36524.25);
  A = Z + 1 + alpha - alpha / 4;
  B = A + 1524;
  C = (int) ((B - 122.1) / 365.25);
  D = (long) (365.25 * C);
  E = (int) ((B - D) / 30.6001);
  *dd = B - D - floor (30.6001 * E) + F;
  if (E < 14)
    *mm = E - 1;
  else
    *mm = E - 13;
  if (*mm > 2)
    *yy = C - 4716;
  else
   *yy = C - 4715;

  F=F*24.0;
  return F;
}
/****************************************************************************/
/* Name:    GCalendarToJD						    */
/* Type:    Function                                                        */
/* Purpose: convert Gdate(year,month,day) to Julian Day            	    */
/* Arguments:                                                               */
/* Input : Gregorian date: year:yy, month:mm, day:dd                        */
/* Output:  The Julian Day: JD                                              */
/****************************************************************************/
double GCalendarToJD(int yy,int mm, double dd)
{        /* it does not take care of 1582correction assumes correct calender from the past  */
int A, B, m, y;
double T1,T2,Tr;
  if (mm > 2) {
    y = yy;
    m = mm;
    }
  else {
    y = yy - 1;
    m = mm + 12;
    }
  A = y / 100;
  B = 2 - A + A / 4;
  T1=ip (365.25 * (y + 4716));
  T2=ip (30.6001 * (m + 1));
  Tr=T1+ T2 + dd + B - 1524.5 ;

  return Tr;
}
/****************************************************************************/
/* Name:    GLeapYear						            */
/* Type:    Function                                                        */
/* Purpose: Determines if  Gdate(year) is leap or not            	    */
/* Arguments:                                                               */
/* Input : Gregorian date: year				                    */
/* Output:  0:year not leap   1:year is leap                                */
/****************************************************************************/
int GLeapYear(int year)
{

  int T;

     T=0;
     if(year%4==0) T=1; /* leap_year=1; */
     if(year%100==0)
       {
	 T=0;        /* years=100,200,300,500,... are not leap years */
	 if(year%400==0) T=1;  /*  years=400,800,1200,1600,2000,2400 are leap years */
       }

  return T;

}
/****************************************************************************/
/* Name:    GDateAjust							    */
/* Type:    Procedure                                                       */
/* Purpose: Adjust the G Dates by making sure that the month lengths        */
/*	    are correct if not so take the extra days to next month or year */
/* Arguments:                                                               */
/* Input: Gregorian date: year:yg, month:mg, day:dg                         */
/* Output: corrected Gregorian date: year:yg, month:mg, day:dg              */
/****************************************************************************/
void GDateAjust(int *yg,int *mg,int *dg)
{
   int dys;

   /* Make sure that dates are within the correct values */
	  /*  Underflow  */
	 if(*mg<1)  /* months underflow */
	  {
	   *mg=12+*mg;  /* plus as the underflow months is negative */
	   *yg=*yg-1;
	  }

	 if(*dg<1)  /* days underflow */
	  {
	   *mg= *mg-1;  /* month becomes the previous month */
	   *dg=gmonth[*mg]+*dg; /* number of days of the month less the underflow days (it is plus as the sign of the day is negative) */
	   if(*mg==2) *dg=*dg+GLeapYear(*yg);
	   if(*mg<1)  /* months underflow */
	    {
	     *mg=12+*mg;  /* plus as the underflow months is negative */
	     *yg=*yg-1;
	    }
	  }

	  /* Overflow  */
	 if(*mg>12)  /* months */
	  {
	   *mg=*mg-12;
	   *yg=*yg+1;
	  }

	 if(*mg==2)
	     dys=gmonth[*mg]+GLeapYear(*yg);  /* number of days in the current month */
	   else
	     dys=gmonth[*mg];
	 if(*dg>dys)  /* days overflow */
	  {
	     *dg=*dg-dys;
	     *mg=*mg+1;
	    if(*mg==2)
	     {
	      dys=gmonth[*mg]+GLeapYear(*yg);  /* number of days in the current month */
	      if(*dg>dys)
	       {
		*dg=*dg-dys;
		*mg=*mg+1;
	       }
	     }
	    if(*mg>12)  /* months */
	    {
	     *mg=*mg-12;
	     *yg=*yg+1;
	    }

	  }


}
/*
  The day of the week is obtained as
  Dy=(Julian+1)%7
  Dy=0 Sunday
  Dy=1 Monday
  ...
  Dy=6 Saturday
*/

int DayWeek(long JulianD)
{
  int Dy;
  Dy=(JulianD+1)%7;

  return Dy;
}

/****************************************************************************/
/* Name:    HCalendarToJD						    */
/* Type:    Function                                                        */
/* Purpose: convert Hdate(year,month,day) to estimated Julian Day     	    */
/* Arguments:                                                               */
/* Input : Hijrah  date: year:yh, month:mh, day:dh                          */
/* Output:  The Estimated Julian Day: JD                                    */
/****************************************************************************/
double HCalendarToJD(int yh,int mh,int dh)
{
 /*
   Estimating The JD for hijrah dates
   this is an approximate JD for the given hijrah date
 */
 double md,yd;
 md=(mh-1.0)*29.530589;
 yd=(yh-1.0)*354.367068+md+dh-1.0;
 yd=yd+1948439.0;  /*  add JD for 18/7/622 first Hijrah date */

 return yd;
}
/****************************************************************************/
/* Name:    JDToHCalendar						    */
/* Type:    Procedure                                                       */
/* Purpose: convert Julian Day to estimated Hdate(year,month,day)	    */
/* Arguments:                                                               */
/* Input:  The Julian Day: JD                                               */
/* Output : Hijrah date: year:yh, month:mh, day:dh                          */
/****************************************************************************/
void JDToHCalendar(double JD,int *yh,int *mh,int *dh)
{
 /*
   Estimating the hijrah date from JD
 */
 double md,yd;

 yd=JD-1948439.0;  /*  subtract JD for 18/7/622 first Hijrah date*/
 md=mod(yd,354.367068);
 *dh=mod(md+0.5,29.530589)+1;
 *mh=(md/29.530589)+1;
 yd=yd-md;
 *yh=yd/354.367068+1;
 if(*dh>30) {*dh=*dh-30;(*mh)++;}
 if(*mh>12) {*mh=*mh-12;(*yh)++;}

}
/****************************************************************************/
/* Name:    JDToHACalendar						    */
/* Type:    Procedure                                                       */
/* Purpose: convert Julian Day to  Hdate(year,month,day)	    	     */
/* Arguments:                                                               */
/* Input:  The Julian Day: JD                                               */
/* Output : Hijrah date: year:yh, month:mh, day:dh                          */
/****************************************************************************/
void JDToHACalendar(double JD,int *yh,int *mh,int *dh)
{
   int  yh1,mh1,dh1;
   int  yh2,mh2,dh2;
   int  yg1,mg1,dg1;
   int  yg2,mg2,dg2;
   int  df,dw2;
  int flag;
  long J;
  double GJD,HJD;


    JDToHCalendar(JD,&yh1,&mh1,&dh1);  /* estimate the Hdate that correspond to the Gdate */
    HJD=HCalendarToJDA(yh1,mh1,dh1);   // get the exact Julian Day
    df=JD+0.5-HJD;
    dh1=dh1+df;
    while(dh1>30)
    {
     dh1=dh1-HMonthLength(yh1,mh1);
     mh1++;
     if(mh1>12) {yh1++;mh1=1;}
    }
   if(dh1==30 && HMonthLength(yh1,mh1)<30)
   {
    dh1=1;mh1++;
   }
   if(mh1>12)
   {
    mh1=1;yh1++;
   }

//   J=JD+2;  *dayweek=J%7;
   *yh=yh1;
   *mh=mh1;
   *dh=dh1;

}

/**************************************************************************/
double ip(double x)
{ /* Purpose: return the integral part of a double value.     */
double  tmp;

   modf(x, &tmp);
  return tmp;
}
/**************************************************************************/
/*
  Name: mod
  Purpose: The mod operation for doubles  x mod y
*/
int mod(double x, double y)
{
  int r;
  double d;

  d=x/y;
  r=d;
  if(r<0) r--;
  d=x-y*r;
  r=d;
 return r;
}

/**************************************************************************/
int IsValid(int yh, int mh, int dh)
{ /* Purpose: returns 0 for incorrect Hijri date and 1 for correct date      */
  int valid;
  valid=1;
  if(yh<HStartYear ||   yh>HEndYear)     valid=0;
  if(mh<1 || mh>12 || dh<1)
      valid=0;
   else
     if(dh>HMonthLength(yh,mh))   valid=0;

  return valid;
}
/**************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -