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

Write a program code in C. 1. Read rocket,txt. rocket.txt contains acceleration

ID: 3817366 • Letter: W

Question

Write a program code in C.

1. Read rocket,txt. rocket.txt contains acceleration data.

2. Find the maximum of the acceleration. Print it on the screen.

3. Find the positive acceleration and write it on a file report.txt

rocket1.txt Notepad File Editt Format View Hel 24 1.0000000e+01 2.9265380e+03 5.0821200e+ 02 4.3231640e+01 2.0000000e+01 1.0170240e+04 9.2798610e+02 4.072 31.80e+01 3.0000000e+01 2.1486260e+04 1.18324, 20e+03 1.0328000e+01 4.0000000e+01 3.3835080e+04 1.1882285e+03 9.3307 000e+00 5.0000000e+01 4 5250830e+04 1.08997 05e+03 1.0320900e+01 6.0000000e+01 5. 56344 90e+ 04 9.89356 50e+02 9.801 9000e+00 7.0000000e+01 6.5037960e+04 8.9134700e+02 9. 8000000e+00 8.0000000e+01 7.34614 30e+04 7.93347 50e+02 9.7999000e+00 9.0000000e+01 8.0904 910e+04 6.95347 50e+02 9.8001000e+00 1.0000000e+02 8.73683800e+04 5.9734700e+ 02 -9. 8000000e+00 1.1000000e+02 9.28518 50e+04 4.9934 700e+02 9. 8000000e+00 1. 2000000e+02 9.7355320e+04 4.0134 750e+02 9.7999000e+00 1.3000000e+02 1.0087880e+05 3.0334400e+02 9.8008000e+00 1.4000000e+02 1.0342220e+05 2.0534 500e+02 9.7990000e+00 1. 5000000e+ 02 1.0498 570e+05 1.3402000e+02 4.4660000e+00 1.6000000e+02 1.06102 60e+05 2.6304000e+02 3.0270000e+01 1. 7000000e+02 1.1024 650e+05 6.7618500e+02 5.2359000e+ 01 1.8000000e+02 1.1962630e+05 1.2929950e+03 7.1003000e+01 1.9000000e+02 1.3610640e+05 2.1234700e+03 9.5092000e+01 2.0000000e+02 1.6209570e+05 3.1700000e+03 1.1421400e+02 2.1000000e+02 1.9950640e+05 3.83400 50e+03 1.8587000e+01 2.2000000e+02 2.3877580e+05 3.87794 50e+03 9.7990000e+00 2.3000000e+02 2.77065 30e+05 3.7799500e+03 9. 8000000e+00 2.4000000e+02 3.1437480e+05 3.681 9500e+03 9. 8000000e+00

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
FILE *filePointer;
double arrayData[4];
double maxAcc = 0;
   double positiveAcc = 0;
char buffer[256];
   // opening file
filePointer = fopen("rocket.txt", "r");

if(filePointer == NULL)
{
fprintf(stderr,"Unable to open file");
exit(EXIT_FAILURE);
}

while( fgets(buffer,sizeof(buffer),filePointer) != NULL )
{
       // reading line by line
sscanf(buffer, "%ld %1d %1d %1d", &arrayData[0], &arrayData[1], &arrayData[2], &arrayData[3]);
       // calculating maximum acceleration
       if(arrayData[0] > maxAcc){
           maxAcc = arrayData[0];
       }
       if(arrayData[1] > maxAcc){
           maxAcc = arrayData[1];
       }
       if(arrayData[2] > maxAcc){
           maxAcc = arrayData[2];
       }
       if(arrayData[3] > maxAcc){
           maxAcc = arrayData[3];
       }
       // calculating positive acceleration
       if((arrayData[1] - arrayData[0] ) > positiveAcc){
           positiveAcc = arrayData[1] - arrayData[0];
       }
       if((arrayData[2] - arrayData[1] ) > positiveAcc){
           positiveAcc = arrayData[2] - arrayData[1];
       }
       if((arrayData[3] - arrayData[2] ) > positiveAcc){
           positiveAcc = arrayData[3] - arrayData[2];
       }
      
}

// closing file
   fclose(filePointer);
   // printing results
   printf("Maximum acceleration: %ld ",maxAcc);
   printf("Positive acceleration: %ld ",positiveAcc);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote