I have tried everything to my knowledge and am having no luck. Arrays are not su
ID: 675244 • Letter: I
Question
I have tried everything to my knowledge and am having no luck. Arrays are not supposed to be used.
A critical path analysis is a technique used to determine the 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, and the number of days required to complete the task. The data have been stored such that all the task data for event 1 are followed by all the task data for event 2, and so on.
Input file:
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 using above data file (must prompt user for file names- input and output) to read in the critical path information and write reports. Print reports (3 reports) to an output file as below:
Print a project completion timetable that lists each event number, the maximum number of days for a task within the event, and the total number of days for the project completion.
Print the event number and task number for all tasks requiring more than 5 days.
Print a report that lists the number of each event and a count of the number of tasks within the event.
** use only one input file and one output file
SAMPLE OUTPUT:
Enter input file name : cri.dat
Enter output file name: criout.dat
(This is a sample of output file)
Event Maximum Number Days for a Task
1 6
2 5
3 4
4 7
5 4
Project Duration : 26 days
Tasks requiring more than 5 days
Event Task Days
1 27 6
4 26 7
4 27 7
Event and Number of Tasks
1 3
2 1
3 2
4 3
5 1
Explanation / Answer
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define FILENAME "path1.txt"
int main(void)
{
/* Declare and initialize variables. */
int event, task, days, total=0, number=0, difference=0,
loopcount=0;
/* Open the file */
FILE *path;
path = fopen(FILENAME,"r");
/* Close the file if NULL */
if(path == NULL)
printf("Error opening input file. ");
else
{
/* Create a while loop as long as it is equal to 3 */
while ((fscanf(path,"%i %i %i", &event, &task, &days)) == 3)
{
/* Calculates the difference btwn the current & previous events */
difference = event - number;
/* If number is equal to the event, add task to the event */
if (number == event)
{
total = total + task;
}
else
/* If number is not equal to the event or zero, print the total */
if (number != 0)
{
printf("Event number %i has %i tasks. ",number,total);
total = task;
}
if (difference > 1)
{
for(loopcount = number+1; loopcount < event; loopcount = loopcount+1)
printf("Event number %i has 0 tasks. ",loopcount);
}
number = event;
}
printf("Event number %i has %i task(s). ",number,total);
}
/* Close file and exit program. */
fclose(path);
return 0;
}