Am working upon an application that registers the leave status of the employees, not more than a 1/10 of the employees should go for leave at the same time and an employee has to spend 30 days on leave.The application should also show when each employee will get their leave.Any one to help me come up with a c code of this program? Thanx
Code: #include <stdio.h> #include <time.h> /* this is not a complete program but it should be easy to complete and convert to a working program */ /* http://msdn.microsoft.com/en-us/library/w4ddyt9h%28v=vs.71%29.aspx - for time [URL=http://www.go4expert.com/articles/c-functions-t29953/]functions in C[/URL] */ typedef struct tm TIMESTRUCT, *TIMESTRUCTPTR; typedef struct { int empno; char empname[ 30 ]; TIMESTRUCT leavefrom, leavetill; } LEAVEINFO, *LEAVEINFOPTR; int datecomp(TIMESTRUCTPTR firstptr, TIMESTRUCTPTR secondptr); double overlappercent(LEAVEINFOPTR leavearray, int empcount, LEAVEINFOPTR curleaveptr); int datecomp(TIMESTRUCTPTR firstptr, TIMESTRUCTPTR secondptr) { /* return 1 if first date > second date 0 if first date == second date -1 if first date < second date */ int result = 0; if( firstptr -> tm_year > secondptr -> tm_year ) result = 1; else if( firstptr -> tm_year < secondptr -> tm_year ) result = -1; else /* same year */ { if( firstptr -> tm_mon > secondptr -> tm_mon ) result = 1; else if( firstptr -> tm_mon < secondptr -> tm_mon ) result = -1; else /* same month */ { if( firstptr -> tm_mday > secondptr -> tm_mday ) result = 1; else if( firstptr -> tm_mday < secondptr -> tm_mday ) result = -1; } } return result; } double overlappercent(LEAVEINFOPTR leavearray, int empcount, LEAVEINFOPTR curleaveptr) { int i; double numoverlap, dblempcount, pct = 0.0; LEAVEINFOPTR liptr; TIMESTRUCT leave_date; dblempcount = (double) empcount; leave_date = curleaveptr -> leavefrom; while( datecomp(&leave_date , &(curleaveptr -> leavetill)) <= 0 && pct >= 0.0 && pct < 10.0 ) { /* init numoverlap to 1 since current leave record to be also taken into account for calculating 10% */ for( i = 0, numoverlap = 1.0; i < empcount; i++ ) { liptr = leavearray + i; /* curleaveptr is (pointer to) the record of employee whose leave is being considered leavearray holds the leave records of employees already sanctioned we want to make sure that on any day of the proposed leave period the absence %age < 10 */ /* if date being checked > end_leave_date OR < start_leave_date of current leave record there is no overlap so DONT increment ELSE increment */ if( datecomp( &leave_date, &(liptr -> leavetill) ) > 0 || datecomp( &leave_date, &(liptr -> leavefrom) ) < 0 ) ; else numoverlap += 1.0; } pct = numoverlap * 100.0 / dblempcount; leave_date.tm_mday += 1; /* increment the date */ if( mktime(&leave_date) == (time_t) -1 ) /* convert incremented date to struct tm */ pct = -1.0; /* error in conversion */ } return pct; } void main() { /* LEAVEINFO leavearray[ MAX_LEAVE ], curleave; int numleave; numleave = read_existing_leave_records_from_file(leavearray); // your code do { get_leave_particulars(&curleave); // your code if( overlappercent(leavearray, numleave, &curleave) < 10.0 ) leavearray[ ++numleave ] = curleave; } while( more_leave_records ); */ return; }