A critical-path analysis is a technique used to determine the schedule for a pro
ID: 3681738 • Letter: A
Question
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, 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 event 1 are followed by all the task data for event 2, and so on. Thus, a typical set of data might be as follows:
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
1.1 Write a program to read the critical-path information and 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.
1.2 Write a program to read the critical-path information and print a report that liststhe event number and task number for all tasks requiring more than five days.
PLEASE ANSWER IN C++ LANGUAGE!
Explanation / Answer
/****** c++ code to 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. ****/
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
FILE *infp, *outfp;
int event, task, days, partevent, maxday = 0, totday;
if ((infp = fopen("1.txt", "r"))==NULL)
{
printf("Input file cannot be opened ");
return -1;
}
if ((outfp = fopen("output1.txt", "w"))==NULL)
{
printf("Output file cannot be opened ");
return -1;
}
fprintf(outfp, "Project completion timetable ");
fprintf(outfp, "--------------------------------------------------- ");
fprintf(outfp, "Event Num of tasks Max num.of days ");
fprintf(outfp, "----- ------------- -------------- ");
partevent = 1;
totday=0;
int t = 0;
while(fscanf(infp, "%d %d %d",&event, &task, &days)==3)
{
if(partevent!=event)
{
fprintf(outfp,"%d %d %d ", partevent, t, maxday);
totday +=maxday;
t = 1;
maxday = days;
partevent = event;
}
else
{
t++;
if(days > maxday)
{
maxday=days;
}
}
}
if(partevent!=-1)
{
fprintf(outfp,"%d %d %d ", partevent, t, maxday);
totday +=maxday;
}
fprintf(outfp, "--------------------------------------------------- ");
fprintf(outfp,"Total number of days to finish the project: %d ", totday);
fclose(infp);
fclose(outfp);
return 0;
}
/****** c++ code to print a report that liststhe event number and task number for all tasks requiring more than five days. ********/
#include <iostream>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
FILE *infp, *outfp;
int event, task, days, partevent, maxday = 0, totday;
if ((infp = fopen("1.txt", "r"))==NULL)
{
printf("Input file cannot be opened ");
return -1;
}
if ((outfp = fopen("output1.txt", "w"))==NULL)
{
printf("Output file cannot be opened ");
return -1;
}
fprintf(outfp, "Tasks requiring more than five days. ");
fprintf(outfp, "--------------------------------------------------- ");
fprintf(outfp, "Event Tast number ");
fprintf(outfp, "----- ----------- ");
while(fscanf(infp, "%d %d %d",&event, &task, &days)==3)
{
if(days > 5)
fprintf(outfp,"%d %d ", event, task);
}
fclose(infp);
fclose(outfp);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.