1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
//This program will find the day from any date between 45BC to 9999AD.
//It uses the Julian Calendar between the dates 45BC and 1752AD.
//It assumes 45BC (the year the Julian calendar was introduced) is a leap year.
//The year does not exist, 3BC, 2BC, 1BC, 1AD....
//Type 'config' to change the date the Gregorian calendar takes effect.
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Collect Data
int england=1752;
start:
cout << "\nDDDDD tt";
cout << "\nDD DD aa aa tt eee";
cout << "\nDD DD aa aaa tttt ee e";
cout << "\nDD DD aa aaa tt eeeee";
cout << "\nDDDDDD aaa aa tttt eeeee\n";
cout << "\n CCCCC lll lll tt";
cout << "\nCC C aa aa lll cccc uu uu lll aa aa tt oooo rr rr";
cout << "\nCC aa aaa lll cc uu uu lll aa aaa tttt oo oo rrr r";
cout << "\nCC C aa aaa lll cc uu uu lll aa aaa tt oo oo rr";
cout << "\n CCCCC aaa aa lll ccccc uuuu u lll aaa aa tttt oooo rr";
cout << "\n\nby Rik Potts";
string start;
cout << "\n\nEnter 'go' to begin or type 'config' for configuration: ";
cin >> start;
if (start!="go" && start!="config")
{
cout << start << " is not a valid entry. Please try again\n\n";
goto start;
}
if (start=="go") goto findday; else goto config;
//Configuration
config:
cout << "\nPlease enter the date you want the Gregorian (modern) calendar to take effect.";
cout << "\n\nDefault is 1752 which is when England began using the Gregorian";
cout << "\ncalendar. The Gregorian calendar was first introduced in 1582";
cout << "\nin Venice, France, Spain, Portugal and Netherlands. Germany in 1583";
cout << ",\nPrussia and Denmark in 1700, Sweden in 1753 and Russia in 1918!\n\n";
cout << "Please enter the date you want the Gregorian calendar to take effect: ";
cin >> england;
cout << "NOTE: You will have to set config each time you run the program.\n\n";
//Find the day (day)
findday:
cout << "The Gregorian (modern) calendar will take effect from " << england;
int day;
cout << "\nPlease enter the day (##): " ;
cin >> day;
if (day>31 || day<1)
{
cout << "\n" << day << " is not a valid day!\nPlease try again\n\n";
goto findday;
}
//Find the month (month)...
month:
string month;
cout << "Please enter the Month (abc): ";
cin >> month;
if (month!="feb" && month!="aug" && month!="mar" && month!="nov"
&& month!="jun" && month!="sep" && month!="dec" && month!="apr"
&& month!="jul" && month!="jan" && month!="oct" && month!="may")
{
cout << "\n" << month << " is not a valid month!\nPlease try again...\n\n";
goto month;
}
if (month=="feb" && day>29)
{
cout << "\nIt is not possible to have " << day << " days in February!";
cout << "\nPlease try again\n\n";
goto findday;
}
//Find the year (date)...
cent:
cout << "\nNOTE: If you need a BC date you DO ";
cout << "NOT need to use a minus sign (-)\n";
//Get the century (cent)
int cent;
cout << "Please enter the first two digits of the year (##__): ";
cin >> cent;
if (cent>99)
{
cout << "\n" << cent << " is not a valid entry.\nYou must enter a number below 99.\n";
goto cent;
}
//Get the year (year)
year:
int year;
cout << "Please enter the last two digits of the year (__##): ";
cin >> year;
if (year>99 || year<0)
{
cout << "\n" << year << " is not a valid entry.\nYou must enter a number below 99\n\n";
goto year;
}
//make the full year (date)
int date, numdate;
date=(100*cent) + year;
numdate=date;
if (date==0)
{
cout << "\nThe date 0000 is not valid because the Julian calendar uses 1BC";
cout << " instead\n\n";
goto cent;
}
//Is it a negative or positive year?...
norp:
string bc;
cout << "Is the year BC? (y/n) : ";
cin >> bc;
if (bc!="y" && bc!="n")
{
cout << bc << " is not a valid option. Please try again...";
goto norp;
}
if (bc=="y") date=-date;
if (date<=-46)
{
cout << "\nYou entered " << numdate << "BC. The Julian calendar was introduced ";
cout << "in 45BC.";
cout << "\nThis makes " << numdate << "BC invalid!\n";
goto cent;
}
int year2;
year2=year/4;
//Process and Validate Data
//Is the year a leap year?...
//Is the year on the gregorian or julian calendar?
int yl=1, nl=0;
if (date>=england) goto gregorian;
//Julian calendar
int jleap;
if (date>0 && (date%4==0)) jleap=yl; else jleap=nl;
if (date<0 && (date%4==-1)) jleap=yl; else jleap=nl;
goto validation;
//Gregorian calendar
gregorian:
int gleap;
gleap = ((date%4==0 && date%100!=0) || date % 400 == 0) ? yl : nl;
//Is the Month and Day combination correct?
validation:
if ((jleap==1 || gleap==1) && month=="feb" && day<=29) goto notfeb;
if ((jleap!=1 || gleap!=1) && month=="feb" && day==29)
{
cout << "\nThe 29th February is not a valid date because " << date;
cout << " \nisnt a leap year!\nPlease try again from the beginning\n\n";
goto findday;
}
if (month!="feb") goto notfeb;
if (!(day<=28 && day>=1))
{
cout << day << "\n is not a valid day!\nPlease try again\n\n";
goto findday;
}
notfeb:
if (month!="sep" && month!="apr" && month!="jun" && month!="nov") goto nsajn;
if (!(day<=30 && day>=1))
{
cout << day << "\n is not a valid day!\nPlease try again\n\n";
goto findday;
}
nsajn:
if (!(day<=31 && day>=1))
{
cout << day << "\n is not a valid day!\nPlease try again\n\n";
goto findday;
}
//Interpret Data
//Calculate the Monthcode
int monthcode;
if (month=="aug") monthcode=0;
if (month=="feb" || month=="mar" || month=="nov") monthcode=1;
if (month=="jun") monthcode=2;
if (month=="sep" || month=="dec") monthcode=3;
if (month=="apr" || month=="jul") monthcode=4;
if (month=="jan" || month=="oct") monthcode=5;
if (month=="may") monthcode=6;
//Which calendar to use?
if (date>=england) goto gregoriansum;
//Is the leap year compensation required?
int ujleap, ugleap;
ujleap=jleap;
ugleap=gleap;
if (month!="jan" && month!="feb") ujleap=nl;
if (month!="jan" && month!="feb") ugleap=nl;
//Julian Formula...
//(Day + MonthCode + Year + Year/4 + 5 – Century – isLeapJanFeb?) % 7
int jresult;
if (date<0) jresult=(day + monthcode - year - (year2) + 5 - cent )%(-7);
else
jresult=(day + monthcode + year + (year2) + 5 - cent - ujleap)%7;
goto weekday;
//Gregorian Formula...
gregoriansum:
//(Day + MonthCode + Year + Year/4 – 2×(Century%4) – isLeapJanFeb?) % 7
int gresult;
gresult=(day + monthcode + year + (year2) - (2*(cent%4)) - ugleap)%7;
//Assign day code to word.
weekday:
int weekday;
string result;
weekday = (date<england) ? jresult : gresult;
if (weekday==0) result="Monday";
if (weekday==1 || weekday==-6) result="Tuesday";
if (weekday==2 || weekday==-5) result="Wednesday";
if (weekday==3 || weekday==-4) result="Thursday";
if (weekday==4 || weekday==-3) result="Friday";
if (weekday==5 || weekday==-2) result="Saturday";
if (weekday==6 || weekday==-1) result="Sunday";
| |