I know this long to read but please i really need help, I attempt this problem the best i could although I'm a beginner on this stuff, I'm not really sure if what i did makes much sense but i hope you can understand it. I just followed similar examples i have with me.
Critical Path Analysis. A critical path analysis is a technique used to determine the time schedule for a project. This information is important in the planning stages before a project is begun, and it is also useful to evaluate the progress of a project that is partially completed. One method for this analysis starts by dividing a project into sequential events and then dividing each event into various tasks. Although one event must be completed before the next one is started, various tasks within an event can occur simultaneously. The time it takes to complete an event, therefore, depends on the number of days required to finish its longest task. Similarly, the total time it takes to finish a project is the sum of time it takes to finish each event.
Assume that the critical path information for a major construction project has been stored in a data file. Each line of the data file contains an event number, a task number, and the number of days required to complete the task. The data have been stored such that all the task data for the first event are followed by all the task data for the second event, and so on. A typical set of data is shown in the following table.
Event__Task___Number of Days
1______15_____3
1______27_____6
1______36_____4
2______15_____5
3______18_____4
3______26_____1
4______15_____2
4______26_____7
4______27_____7
5______16_____4
Write a program to read the critical path information from critical1.txt file and to print a project completion timetable into output1.txt.
Timetable lists each event number, number of tasks under this event, the maximum number of days for this event, and the total number of days for the project completion.
For example, your output1.txt will look like as follows based on the above input file:
Project completion timetable
---------------------------------------------------------------
Event____Num of tasks_____Max num.of days
------ ----------------- ----------------------
1__________3_________________6
2__________1_________________5
3__________2_________________4
4__________3_________________7
5__________1_________________4
---------------------------------------------------------------
Total number of days to finish the project: 26 days
Code:
#include <stdio.h>
int main()
{
FILE *infp, *outfp;
int max(numevents, numtasks, maxnumdays, totalnumdays);
int min(numevents, numtasks, maxnumdays, totalnumdays);
if ((infp = fopen("critical1.txt", "r"))==NULL) {
printf("input file cannot be opened\n");
return -1;
}
if ((outfp = fopen("output1.txt", "w"))==NULL){
printf("output file cannot be opened\n");
return -1;
}
while( fscanf (infp, "%d %d %d %d", &numevents, &numtasks, &maxnumdays, &totalnumdays ) == 4) {
if (numevents > maxnumdays)
return numevents;
else
return maxnumdays;
}
if (numevents < maxnumdays)
return numevents;
else
return maxnumdays;
}
fprintf(outfp, "Total number of days: %d %d %d \n", numtasks, maxnumdays, numtasks + maxnumdays); }
fclose(infp);
fclose(outfp);
return 0;
}