fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. // Dereceyi Radyana Çevir
  5. double degToRad(double degree) {
  6. return (M_PI / 180) * degree;
  7. }
  8.  
  9. // Radyanı Dereceye Çevir
  10. double radToDeg(double radian) {
  11. return radian * (180 / M_PI);
  12. }
  13.  
  14. // Bir değeri 0 ile 360 arasında tutar
  15. double moreLess360(double value) {
  16. while (value > 360 || value < 0) {
  17. if (value > 360)
  18. value -= 360;
  19. else if (value < 0)
  20. value += 360;
  21. }
  22. return value;
  23. }
  24.  
  25. // Bir değeri 0 ile 24 arasında tutar
  26. double moreLess24(double value) {
  27. while (value > 24 || value < 0) {
  28. if (value > 24)
  29. value -= 24;
  30. else if (value < 0)
  31. value += 24;
  32. }
  33. return value;
  34. }
  35.  
  36. // Ondalık saati Saat ve Dakikaya çevir
  37. void doubleToHrMin(double number, int &hours, int &minutes) {
  38. hours = static_cast<int>(floor(moreLess24(number)));
  39. minutes = static_cast<int>(floor(moreLess24(number - hours) * 60));
  40. }
  41.  
  42. // Namaz vakitlerini hesaplar
  43. void calcPrayerTimes(int year, int month, int day,
  44. double longitude, double latitude, int timeZone,
  45. double fajrTwilight, double ishaTwilight,
  46. double &fajrTime, double &sunRiseTime, double &zuhrTime,
  47. double &asrTime, double &maghribTime, double &ishaTime) {
  48. double D = (367 * year) - ((year + static_cast<int>((month + 9) / 12)) * 7 / 4) + ((275 * month / 9) + day - 730531.5);
  49. double L = 280.461 + 0.9856474 * D;
  50. L = moreLess360(L);
  51. double M = 357.528 + 0.9856003 * D;
  52. M = moreLess360(M);
  53. double Lambda = L + 1.915 * sin(degToRad(M)) + 0.02 * sin(degToRad(2 * M));
  54. Lambda = moreLess360(Lambda);
  55. double Obliquity = 23.439 - 0.0000004 * D;
  56. double Alpha = radToDeg(atan(cos(degToRad(Obliquity)) * tan(degToRad(Lambda))));
  57. Alpha = moreLess360(Alpha);
  58. Alpha = Alpha - (360 * static_cast<int>(Alpha / 360));
  59. Alpha = Alpha + 90 * (floor(Lambda / 90) - floor(Alpha / 90));
  60. double ST = 100.46 + 0.985647352 * D;
  61. double Dec = radToDeg(asin(sin(degToRad(Obliquity)) * sin(degToRad(Lambda))));
  62. double Durinal_Arc = radToDeg(acos((sin(degToRad(-0.8333)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  63. double Noon = Alpha - ST;
  64. Noon = moreLess360(Noon);
  65. double UT_Noon = Noon - longitude;
  66.  
  67. ////////////////////////////////////////////
  68. // Namaz Vakitlerinin Hesaplanması
  69. //////////////////////////////////////////
  70.  
  71. // Temkin değerleri
  72. double fajrTemkin = 0.0;
  73. double sunriseTemkin = -7.0 / 60.0;
  74. double zuhrTemkin = 4.0 / 60.0;
  75. double asrTemkin = 4.0 / 60.0;
  76. double maghribTemkin = 7.0 / 60.0;
  77. double ishaTemkin = 0.0;
  78.  
  79. // Öğle vakti [yerel öğle]
  80. zuhrTime = (UT_Noon / 15 + timeZone) + zuhrTemkin;
  81.  
  82. // İkindi vakti
  83. double Asr_Alt = radToDeg(atan(1 + tan(degToRad(fabs(latitude - Dec)))));
  84. double Asr_Arc = radToDeg(acos((sin(degToRad(90 - Asr_Alt)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  85. Asr_Arc = Asr_Arc / 15;
  86. asrTime = (zuhrTime + Asr_Arc) + asrTemkin;
  87.  
  88. // Sabah vakti
  89. sunRiseTime = (zuhrTime - (Durinal_Arc / 15)) + sunriseTemkin;
  90.  
  91. // Akşam vakti
  92. maghribTime = (zuhrTime + (Durinal_Arc / 15)) + maghribTemkin;
  93.  
  94. double Esha_Arc = radToDeg(acos((sin(degToRad(ishaTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  95. ishaTime = (zuhrTime + (Esha_Arc / 15)) + ishaTemkin;
  96.  
  97. double Fajr_Arc = radToDeg(acos((sin(degToRad(fajrTwilight)) - sin(degToRad(Dec)) * sin(degToRad(latitude))) / (cos(degToRad(Dec)) * cos(degToRad(latitude)))));
  98. fajrTime = (zuhrTime - (Fajr_Arc / 15)) + fajrTemkin;
  99.  
  100. return;
  101. }
  102.  
  103. int main() {
  104. double fajr, sunRise, zuhr, asr, maghrib, isha;
  105. calcPrayerTimes(2024, 11, 12, 32.8597, 39.9334, 3, -19, -17,
  106. fajr, sunRise, zuhr, asr, maghrib, isha);
  107.  
  108. int hours, minutes;
  109.  
  110. doubleToHrMin(fajr, hours, minutes);
  111. std::cout << "Fajr: " << hours << ":" << minutes << std::endl;
  112.  
  113. doubleToHrMin(sunRise, hours, minutes);
  114. std::cout << "Sunrise: " << hours << ":" << minutes << std::endl;
  115.  
  116. doubleToHrMin(zuhr, hours, minutes);
  117. std::cout << "Zuhr: " << hours << ":" << minutes << std::endl;
  118.  
  119. doubleToHrMin(asr, hours, minutes);
  120. std::cout << "Asr: " << hours << ":" << minutes << std::endl;
  121.  
  122. doubleToHrMin(maghrib, hours, minutes);
  123. std::cout << "Maghrib: " << hours << ":" << minutes << std::endl;
  124.  
  125. doubleToHrMin(isha, hours, minutes);
  126. std::cout << "Isha: " << hours << ":" << minutes << std::endl;
  127. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Fajr: 5:55
Sunrise: 7:27
Zuhr: 12:36
Asr: 15:21
Maghrib: 17:46
Isha: 19:7