Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Friday the Thirteenth Download Source Code
Author Details Code Information
Coding_Guy ( Gleb Sorokosh )

Pinned 5 Codes
Posted 5 Coding Articles

Send A Message
View Coders Profile
Language C++
Expires Never
Length 2,160 Characters (90 Lines)
Password no password
  1. #include<fstream>
  2. using namespace std;
  3.  
  4. int whatDate (int date, bool leap)
  5. {
  6.             if (leap)
  7.           {
  8.                                 //january february march april may june july august september october                    november
  9.              if (date == 32 || date == 61 || date == 92 || date == 122 || date == 153 || date == 183 || date == 214 || date == 245 || date == 275 || date == 306 || date == 336)
  10.              return 0;
  11.             }
  12.  
  13.             else
  14.           {
  15.                         //january february march april may june july august september october                    november
  16.              if (date == 32 || date == 60 || date == 91 || date == 121 || date == 152 || date == 182 || date == 213 || date == 244 || date == 274 || date == 305 || date == 335)
  17.              return 0;
  18.             }
  19.  
  20.           return date;
  21. }
  22.  
  23. bool isLeap (int year)
  24. {
  25.           if ((!(year % 100) && !(year % 400)) || (!(year % 4) && !(year % 100)))
  26.            return true;
  27.           else
  28.                     return false;
  29. }
  30.  
  31. /////////////////////////////////////MAIN//////////////////////////////////
  32. int main()
  33. {
  34.  
  35.           ofstream fout("friday.out");
  36.           ifstream fin("friday.in");
  37.  
  38.           int daysWeek[7];
  39.  
  40.           int temp(0);
  41.  
  42.           short totYears (0);
  43.           fin>> totYears;
  44.  
  45.             for (int i (1900) ; i < 1900 + totYears ; i++)//keeps track of years
  46.           {
  47.                     if (isLeap(i))//checks if it's a leap year
  48.                     {
  49.                         for(int j(1) ; j <= 366 ; )
  50.                               {
  51.                                           temp = !whatDate(j, true) ? 1 : temp + 1;//temp has higher scope
  52.                                           for (int week(0) ; week < 7 ; week++)
  53.                                           {
  54.                                                    ++j;
  55.  
  56.                                                   if (temp == 13)
  57.                                                    daysWeek[week]++;
  58.  
  59.                                                   ++temp;
  60.                                         }
  61.                               }
  62.                     }
  63.  
  64.                     else
  65.                     {
  66.                         for(int j(1) ; j <= 365 ; )
  67.                               {
  68.                                           temp = !whatDate(j, false) ? 0 : temp + 1;//temp has higher scope
  69.                                           for (int week(0) ; week < 7 ; week++)
  70.                                           {
  71.                                                    ++j;
  72.  
  73.                                                   if (temp == 13)
  74.                                                    daysWeek[week]++;
  75.  
  76.                                                   ++temp;
  77.                                         }
  78.                               }
  79.                     }
  80.           }
  81.  
  82.           fout<<daysWeek[5] <<" "
  83.            <<daysWeek[6] <<" "
  84.                     <<daysWeek[0] <<" "
  85.            <<daysWeek[1] <<" "
  86.                     <<daysWeek[2] <<" "
  87.            <<daysWeek[3] <<" "
  88.                     <<daysWeek[4];
  89.           return 0;
  90. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved