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

ENGR 200 SPRING 2016 P5: SEISMIC HOLES AND BLASTING (using input/output data fil

ID: 3672736 • Letter: E

Question

ENGR 200 SPRING 2016 P5: SEISMIC HOLES AND BLASTING (using input/output data files, for loops, if/else structures, and one-dimensional arrays) DUE: Feb. 29, 2016 at 11:59 pm, CT (Mon/Wed section) Mar. 1.2016 at 11:59 pm, CT (Tues/Thur sections, including DEDP) POINTS: 55 INTRODUCTION: Oil exploration is being conducted by drilling holes and blasting with specific amounts of dynamite. To obtain useful seismic readings, a specific ratio between the amount of dynamite and the depth of the hole is needed. The ideal powder charge to depth-of-hole ration is 1:3. For blasting operations each stick of dynamite will be 2 teet long and will weigh 5 pounds. Since the actual powder charge will generally not be equal to the ideal powder charge, compute the actual powder charge in 5 pound increments. Here is an example: Hole depth-85 feet Ideal powder to hole depth ratio 85/3-28.33333 feet Ideal number of sticks 28.33333/2-14.16666 Ideal powder charge -14.16666 5-70.83333 pounds Actual number of sticks- 14 Actual charge 14'3-70 pounds An input data file called explore contains exploration information for each well site. The first record line of the input file is the control number which defines the number of sites to be read into the program. Each succeeding record line has two columns, where the first column is the well site number and the second column is the hole depth of the well in feet. The input file is comma delimited. ASSIGNMENT: Write a C program that will read the required values from the input file into two one-dimensional arrays: one array for the well site number and one array for the hole depth Using the hole depth array, compute the hole to depth ration, the ideal number of sticks, the ideal powder charge, the actual powder charge, and the actual number of sticks. Your program will produce a report in tabular format. Print the table to the computer screen and to an output file called blasting Once the program is working, modify the program to account for any hole depth that is less than 30 feet Instead of printing the normal column items, for any hole that is less than 30 feet, print the well site number well depth, and then print a message that the hole is too shallow. The output format is shown on page 2. A partial flowchart is provided on page 3.

Explanation / Answer

main.c

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

int main() {
   FILE* reader = fopen("input.txt", "r");
   FILE* writer = fopen("blasting.txt", "w");
   int controlNumber;
   fscanf(reader, "%d", &controlNumber);

   // create an array
   int wellSiteNumber[100];
   int holeDepths[100];

   int i;
   for (i = 0; i < controlNumber; ++i) {
       fscanf(reader, "%d, %d", wellSiteNumber + i, holeDepths + i);
   }

   // output to file
   fprintf(writer, " DAILY DRILLING REPORT ");
   fprintf(writer, "Site ID Depth Ideal Powder Actual Powder Sticks ");
   fprintf(writer, " (ft) Charge (lbs) Charge (lbs) ");

   // output to screen
   printf(" DAILY DRILLING REPORT ");
   printf("Site ID Depth Ideal Powder Actual Powder Sticks ");
   printf(" (ft) Charge (lbs) Charge (lbs) ");

   for (i = 0; i < controlNumber; ++i) {
       double idealPowderToHoldDepthRatio = holeDepths[i] / 3.0;
       double idealNumberOfSticks = idealPowderToHoldDepthRatio / 2.0;
       double idealPowerCharge = idealNumberOfSticks * 5;
       int actualNumberOfSticks = (int) idealNumberOfSticks;
       int actualCharge = actualNumberOfSticks * 5;

       if (holeDepths[i] < 30) {
           fprintf(writer, "%d **Hole too shallow for blasting** ", wellSiteNumber[i]);
           printf("%7d **Hole too shallow for blasting** ", wellSiteNumber[i]);
       } else {
           fprintf(writer, "%7d %5d %12lf %13lf %6d ",
               wellSiteNumber[i], holeDepths[i], idealPowerCharge, actualCharge, actualNumberOfSticks);
           printf("%7d %5d %12lf %13lf %6d ",
               wellSiteNumber[i], holeDepths[i], idealPowerCharge, actualCharge, actualNumberOfSticks);
       }
   }
   return 0;
}

input.txt

5
1, 50
2, 100
3, 10
4, 25
5, 100

blasting.txt

               DAILY DRILLING REPORT              

Site ID   Depth   Ideal Powder   Actual Powder   Sticks
    (ft)   Charge (lbs)   Charge (lbs)
1   50   41.666667   0.000000   8
2   100   83.333333   0.000000   16
3 **Hole too shallow for blasting**
4 **Hole too shallow for blasting**
5   100   83.333333   0.000000   16

NOTE: output is properly formatted than it looks here.