Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi I got this answer for ( C program ) and I want it to be in ( C++ program ) ex

ID: 3631710 • Letter: H

Question

hi

I got this answer for ( C program ) and I want it to be in ( C++ program )

examples:
#include <stdio.h> to be # include < iostream >
printf to be cout
scanf to be cin
and for while condition and loop and others too
and so on ......


the program is :

#include <stdio.h>
int main(void)
{ FILE *infp, *outfp;
int event, task, days, partevent, maxday, totday;
if ((infp = fopen("critical1.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, "Event Num of tasks Max num.of days ");
partevent=-1;
totday=0;
while(fscanf(infp, "%d %d %d",&event, &task, &days)==3)

{
if(partevent!=event)
{
if(partevent!=-1)
{
fprintf(outfp,"%d %d %d ", partevent, task, maxday);
totday +=maxday;
}
task=1;
maxday=days;
partevent=event;
}
else
{
task++;
if(maxday<days)
{
maxday=days;
}
}
}
if(partevent!=-1)
{
fprintf(outfp,"%d %d %d ", partevent, task, maxday);
totday +=maxday;
}
fprintf(outfp,"Total number of days to finish the project: %d ", totday);
fclose(infp);
fclose(outfp);
return 0;
}

Explanation / Answer

please rate - thanks

not knowing what the data looks like, I was unable to test this.

message me data and a link to this post and I will make any changes, if there are any problems


#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{ ifstream in;
ofstream out;
int event, task, days, partevent, maxday, totday;
in.open("critical1.txt");       
if(in.fail())           
   { cout<<"input file did not open please check it ";
   system("pause");
   return -1;
   }
out.open("output1.txt");
    if(out.fail())           
   { cout<<"output file did not open please check it ";
   system("pause");
   return -1;
   }
out<< "Project completion timetable ";
out<< "Event Num of tasks Max num.of days ";
partevent=-1;
totday=0;
in>>event;
while(in)
    {in>>task;
     in>>days;
     if(partevent!=event)
         {
          if(partevent!=-1)
             {
              out<< partevent<<" "<<task<<" "<<maxday <<endl;
              totday +=maxday;
              }
          task=1;
          maxday=days;
          partevent=event;
         }
      else
         {
          task++;
          if(maxday<days)
              {
               maxday=days;
               }
          }
      in>>event;
     }
if(partevent!=-1)
{
out<< partevent<<" "<<task<<" "<<maxday <<endl;
totday +=maxday;
}
out<<"Total number of days to finish the project: "<<totday<<" ";
out.close();
in.close();
return 0;
}