Homework Help Question & Answers

Question 9 [13 marks] A file called tanks.dat consists of the width, height and depth values for a number of water...


Question 9 [13 marks] A file called tanks.dat consists of the width, height and depth values for a number of water tanks. The
Question 9 [13 marks] A file called tanks.dat consists of the width, height and depth values for a number of water tanks. The values are all floating point and the units are metres. A typical file is shown below: 10 2.0 2.0 1.0 3.0 0.5 1.5 1.0 2.5 0.5 1.0 1.0 0.25 0.5 0.25 0.25 5.0 1.2 1.3 2.5 1.1 0.6 0.8 0.8 0.8 0.7 0.7 0.6 0.5 0.3 0.2 The first row of the file contains the number of triples of dimensions for each tank i.e. number of lines to read (in this case 10). Each of the rest of the lines contains the width, height and depth of a tank in that order. Your task is to create a C program to read the data in from the file and store it in suitable arrays. Assume the maximum number of triples that could be in the file is 100. Use appropriate error checking to deal with the file not existing. [4 marks for appropriate variables and constants, 4 marks for reading from the file, 5 marks for processing the data, total of 13 marks].
0 0
Next > < Previous
ReportAnswer #1

#include<stdio.h>
#include<stdlib.h>
int main(){

FILE *fp;
fp = fopen("tanks.dat","r");
if (!fp){
   printf("File is not present");
}
else{

   float width[100],height[100],depth[100];
   int nol;// no of lines in the file for the tripplet values
   float wid,he,dep;
   int i=0,j=0,k,result;
   fscanf(fp,"%d",&nol); // reads the first line in the file
   // this while loop is to iterate over the file and get the triplet values
   while(1){

       result = fscanf(fp,"%f %f %f\n",&wid,&he,&dep);
       if (result == EOF) //it checks for end of the file it will break when we came to end of file
           break;

            width[j] = wid; //store the values into respective arrays
        height[j] = he;
        depth[j] = dep;
        j++;

  
   }
   // for printing values
   printf("------------the values of widths are------ \n");
   for (k=0;k<nol;k++){
  
   printf("%f\n",width[k]);
   }

              printf("------------the values of heights are------ \n");
                      for (k=0;k<nol;k++){

                              printf("%f\n",height[k]);
                                  }

                  printf("------------the values of depths are------ \n");
                          for (k=0;k<nol;k++){

                                  printf("%f\n",depth[k]);
                                      }


}
return 0;
}

Know the answer?
Add Answer of:
Question 9 [13 marks] A file called tanks.dat consists of the width, height and depth values for a number of water...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • sume that the first record in a sensor data file contains an integer that specifies the number...

    File ProcessingSpecified Number of RecordsAssume that the first record in a sensor data file contains an integer that specifies the number of records of sensor information that follow.Each of the following lines contains a time and sensor reading. Write a program that generates a summary report to an output file.input.txt (input file)100.0 132.50.1 147.20.2 148.30.3 157.30.4 163.20.5 158.20.6 169.30.7 148.20.8 137.60.9 135.9Sample Output:Number of sensor readings:Average reading:Maximum reading:Minimum reading:Implementation:Output file name should be output.txtInput file name should be input.txt

  • please do question 20 and write clearly ping, Exploring, and Comparing Data In Exercises 17-20, use the following ce...

    please do question 20 and write clearly ping, Exploring, and Comparing Data In Exercises 17-20, use the following cell phone airport data speeds (Mbps) to the given data speed. Percentiles. from Sprint. Find the percentile corresponding 0.3 0.3 0.4 0.4 0.4 0.3 0.3 0.3 0.3 0.2 0.7 0.8 1.0 0.6 0.6 0.5 0.5 0.5 0.5 0.5 2.3 2.4 2.1 2.1 1.6 1.6 1.2 1.2 1.1 1.1 4,0 4.0 3.4 3.6 3,8 3.2 2.7 2.7 2.7 2.5 15.2 30.4 13.0 15.1...

  • QUESTION 1 (15 marks) Studd Enterprises sells big-screen televisions. A concern of management is the number...

    QUESTION 1 (15 marks) Studd Enterprises sells big-screen televisions. A concern of management is the number of televisions sold each day. A recent study revealed the number of days that a given number of televisions were sold. # of TV units sold #of days Answer the questions below. For each part, show your calculations and/or explain briefly how you arrived at your answer, as appropriate or needed. Required: a. Convert the frequency distribution above into a probability distribution (or relative...

  • Question 3 A 10 m square and 7.5 m deep pit is to be excavated in...

    Question 3 A 10 m square and 7.5 m deep pit is to be excavated in a soil with a unit weight of 20 kN/m2. What is the stress relief at 2 m. 5 m and 10 m below the centre point of the bottom of the excavation? b. The circular flexible area is uniformly loaded (q 320 kN/m2). Determine the change in vertical stress: i. at point A At a point 2 m below point A 4 m A...

  • Statistics

    True/FalsePlease indicate if the following statements are true or false.1. The variable of height is an example of a quantitative variable.2. Rating a restaurant by a number of stars is an example of an ordinal level of measurement.3. In a research study, it is always preferable for the researcher to choose his participants as carefully as possible rather than randomly accept samples.4. In the following chart, the height is the independent variable and the age of the tree is the...

  • **This question has been asked and answered once already with OLD data, please note you will...

    **This question has been asked and answered once already with OLD data, please note you will need to visit the website below as stated in the question or go by the table/chart provided at the bottom** Visit the Bureau of Economics Analysis website at www.bea.gov. From the drop-down menu under "Data", click on "by Economics Account". Then click on "National", "Gross Domestic Product" and "Full Release and Tables". Use table 3 (Gross Domestic Product: Level and Change from Preceding Period)....

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
Share Your Knowledge

Post an Article
Post an Answer
Post a Question with Answer

Self-promotion: Authors have the chance of a link back to their own personal blogs or social media profile pages.