// $Id: main.cpp,v 1.2 2004/07/06 12:07:00 loreti Exp $ #define MONDAY_IS_0 // REQUIRED! (snip4.cpp relies on that) // Yes, I know; it is a very very bad policy the inclusion of a source // file. But consider that these files were born as stand-alone // examples, and not as part of a single program. #include "snip0.cpp" #include "snip1.cpp" #include "snip2.cpp" #include "snip3.cpp" #include "snip4.cpp" #include "snip5.cpp" #include "snip6.cpp" void g2j(); void j2g(); void g2f(); void f2g(); void g2w(); using namespace std; static const char * mNames [] = { "???", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static const char * wNames [] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; int main() { while (true) { istringstream iss; string s; int i; cout << "0: Gregorian -> Julian\n"; cout << "1: Julian -> Gregorian\n"; cout << "2: Gregorian -> French\n"; cout << "3: French -> Gregorian\n"; cout << "4: Gregorian -> Week #\n"; cout << "5: Exit\n? "; if (!getline(cin, s)) break; iss.str(s); iss >> i; switch (i) { case 0: g2j(); break; case 1: j2g(); break; case 2: g2f(); break; case 3: f2g(); break; case 4: g2w(); break; case 5: return 0; default: cerr << "Invalid input\n"; break; } } cout << '\n'; return 0; } void g2j() { int day, month, year; long julian; while (true) { istringstream iss; string s; cout << "Day, month, year (or EOF to exit) ? "; if (!getline(cin, s)) break; iss.str(s); iss >> day >> month >> year; try { julian = greg2jul(day, month, year); cout << day << '-' << mNames[month] << '-' << year << " is JD " << julian << endl; } catch (const exception & e) { cerr << "*** EXCEPTION: " << e.what() << endl; } } cin.clear(); } void j2g() { int day, month, year; long julian; while (true) { istringstream iss; string s; cout << "Julian day (or EOF to exit) ? "; if (!getline(cin, s)) break; iss.str(s); iss >> julian; try { jul2greg(julian, day, month, year); cout << "JD " << julian << " is " << day << '-' << mNames[month] << '-' << year << endl; } catch (const exception & e) { cerr << "*** EXCEPTION: " << e.what() << endl; } } cin.clear(); } void g2f() { int day, month, year, fDay, fMonth, fYear; long julian; while (true) { istringstream iss; string s; cout << "Day, month, year (or EOF to exit) ? "; if (!getline(cin, s)) break; iss.str(s); iss >> day >> month >> year; try { julian = greg2jul(day, month, year); jul2french(julian, fDay, fMonth, fYear); cout << day << '-' << mNames[month] << '-' << year << " is "; if (fMonth == 13) cout << sansCulNames[fDay]; else cout << fDay << ' ' << frenchMonthsNames[fMonth]; cout << " an " << roman(fYear) << endl; } catch (const exception & e) { cerr << "*** EXCEPTION: " << e.what() << endl; } } cin.clear(); } void f2g() { int day, month, year, fDay, fMonth, fYear; long julian; while (true) { istringstream iss; string s; cout << "Day, month, year (or EOF to exit) ? "; if (!getline(cin, s)) break; iss.str(s); iss >> fDay >> fMonth >> fYear; try { julian = french2jul(fDay, fMonth, fYear); jul2greg(julian, day, month, year); if (fMonth == 13) cout << sansCulNames[fDay]; else cout << fDay << ' ' << frenchMonthsNames[fMonth]; cout << " an " << roman(fYear) << " is " << day << '-' << mNames[month] << '-' << year << endl; } catch (const exception & e) { cerr << "*** EXCEPTION: " << e.what() << endl; } } cin.clear(); } void g2w() { int day, month, year, wDay; long wNum; while (true) { istringstream iss; string s; cout << "Day, month, year (or EOF to exit) ? "; if (!getline(cin, s)) break; iss.str(s); iss >> day >> month >> year; try { wDay = weekDay(day, month, year); wNum = week(day, month, year); cout << "- " << day << '-' << mNames[month] << '-' << year << " is a " << wNames[wDay] << ", and in the ISO week " << wNum/100 << '-' << wNum%100 << endl; } catch (const exception & e) { cerr << "*** EXCEPTION: " << e.what() << endl; } } cin.clear(); }