TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: STEVEN READ
from: EDWARD RUTLEDGE
date: 1997-06-24 01:25:00
subject: Converting program 1 of 3

/* zztst-x9.cpp 
   Convert Gregorian to Julian 
   Has some improved fail-safe functions. 
   Added the necessary code to be given a date and days hence then 
   return the new date in commercial Gregorian format.  (Is able to go 
   past the year boundry.) 
 
   Needs more fail-safing for the Julian input. 
   (If days > 365 (366 for leap year) then work up the required code to be 
   able to handle the year boundry limits.) 
 
   Fixed the year boundry limits. 
 
   Added negative days failsafe code for date plus days delay.  Added code 
   to handle negative days delay given two dates. 
 
   Added century leap year code.  On centurys that are evenly devisiable by 
   400 the leap year has 366 days.  On "leap years" that are not evenly 
   divisable by 400 the leap year is to have 365 days. 
 
   Use pointers to get to month definations (a memory saving technique). 
   Also added code to further expand the century leap year capability. 
 
   Added the capability of bringing in some of the values from the command 
   line. 
 
   Changed the error codes returned by the exit() function. 
*/ 
 
#include  
#include  
#include  
 
// Variables used by multiple functions (Common) 
long year; 
int month, day, total_days; 
int days_per_month [ 12 ] = 
	{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
char* month_1 [ 3 ] [ 12 ] = 
	{ { "January", "February", "March", 
	  "April", "May", "June", 
	  "July", "August", "September", 
	  "October", "November", "December" }, 
	{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
	  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }, 
	{ "1", "2", "3", "4", "5", "6", 
	  "7", "8", "9", "10", "11", "12" } }; 
 
// Prototype functions 
long to_julian ( );				//Input Gregorian to Julian 
long to_julian ( int, int, long );		//Convert to Julian 
void to_gregorian ( long );			//Convert Julian to Gregorian 
void to_gregorian ( long, int&, int&, int& );	//Convert to Julian 
long leap_year ( long, int );			//Adj Feb if leap year X 1000 
void leap_year ( long );			//Adj Feb if leap year 
int in_day ( int );				//Input day 
int in_month ( );				//Input month 
int Total_days ( int, int );			//Return day of year 
void greg_ ( int& , int& );			//Convert Julian to Greg M&D 
int Days_Between ( long, long );		//Determine days between years 
int Days_in_year ( long );			//Return days in year (long) 
long double char_t_float ( char* );		//Convert char to float pt. 
char character ( char* ); 
 
void main ( int argc, char* argv [ ] ) 
	{ 
	long temp; 
	int month_, day_, year_; 
	int month_dsp = 0; 
	int days = 0; 
	int xtemp = 0; 
	char direction; 
	long start_; 
	long end_; 
	long tempx [ 10 ] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 
	if ( argc == 1 ) 
		{ 
		cout << "\nFrom Gregorian To Julian = 0, " 
		     << "\nFrom julian (to Gregorian) = 1," 
		     << "\nAdd days of Delay to date = 2," 
		     << "\nNumber of days delay Between two dates = 3" 
		     << "\nWhat is the desired function?  "; 
		direction = getche ( ); 
		cout << '\n'; 
		} 
	else 
		{ 
		if ( argc > 9 ) 
			{ 
			cout << "To many input parameters\n"; 
			exit ( 100 ); 
			} 
		direction = character ( argv [ 1 ] ); 
		for ( int j = 2; j < argc; j ++ ) 
			{ 
			tempx [ j ] = char_t_float ( argv [ j ] ); 
			} 
		} 
	switch ( direction ) 
		{ 
		case '0': 
		case 't': 
		case 'T': 
		case 'j': 
		case 'J': 
			if ( argc == 5 ) 
				cout << to_julian 
				     ( tempx [ 2 ], tempx [ 3 ], 
				       tempx [ 4 ] ) % 100000 << endl; 
				else 
				cout << '\n' 
				     << to_julian ( ) % 100000 << endl; 
			break; 
		case '1': 
		case 'f': 
		case 'F': 
		case 'g': 
		case 'G': 
			if ( argc == 4 ) 
				{ 
				if ( tempx [ 3 ] > 2 | tempx [ 3 ] < 0 ) 
					{ 
					cout << "Wrong month specification " 
					     << "(0 = Month, 1 = Mon, 2 = " 
					     << " month number )"; 
					exit ( 120 ); 
					} 
				month_dsp = tempx [ 3 ]; 
				temp = tempx [ 2 ]; 
				} 
			else 
				{ 
				cout << "How do you want the month " 
				     << "displayed?  \n" 
				     << "(0 = Month, 1 = Mon, 2 = " 
				     << "month number)  ";
				cin >> month_dsp; 
				if ( month_dsp > 2 | month_dsp < 0 ) 
					{ 
					cout << "Wrong month specification " 
					     << "(0 = Month, 1 = Mon, 2 = " 
					     << " month number )"; 
					exit ( 121 ); 
					} 
 
>>> 
--- 
 * OFFLINE 1.58 
--- WILDMAIL!/WC v4.12 
---------------
* Origin: Star Tech Diamond Bar, CA 909-396-4227 714-257-1175 (1:218/801.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.