The concrete manufacturer has expanded its study to include

The concrete manufacturer has expanded its study to include more formulations and plants. They have automated the data collection so that the compressive strengths are stored in a file containing a table (2-D array). Each row of the table represents a specific formulation and each column represents a specific plant. Your program should have a main function and 4 other functions as described below. The manufacturer has stated that there will not be more than 50 formulations and not more than 12 plants.

One function should open the file and read the first line that contains the number of formulations (the first value) and number of plants (the second value). Using these values, your function should then read the rest of the data and store the values in a 2-dimensional array. As the compressive strengths are being stored, a message should be output if any compressive strength is not in the range of 15 to 75 MPa. The message should output the formulation, plant and compressive strength as the example below.

The value of 14.56 from plant 1 for formulation 8 is suspect.

The compressive strength should still be stored in the array. The number of formulations and number plants should be sent back to the function call

One function should accept the 2-dimensional array, the number of formulations and number of plants then create a 1-dimensional array containing the minimum compressive strengths for each formulation and create a 1-dimensional array containing the maximum compressive strengths for each formulation This function should call the function to output a 1-dimensional array for the minimum and maximum values before sending these arrays back to the function call.

One function should accept the 2-dimensional array and determine the average compressive strength for each formulation. The average for a each formulation should be calculated without including the maximum and minimum compressive strength for that formulation, therefore this function will need to call the function that calculates the minimum and maximum compressive strengths for each formulation. The average compressive strengths for the formulations should be stored in another 1-dimensional array which is sent back to the function call.

One function that will accept a 1-dimensional array, the number of values stored in the array and a description of what is stored in the array, e.g “minimum compressive strength for each formulation”, “ average compressive strength for each formulation”, etc. The function will then output the description and the values. The values should be output to 4 significant digits;

The main function should prompt the user to enter the filename for the data file and call the function to import the data from the file into a 2-dimensional file. Next main should call the function to calculate the averages of the formulations. The main function should then call the function to output a 1-dimensional array sending the array of averages to the function to calculate the 1-dimensional array.

A data file, “CompStrengths.dat”, has been posted below. However, you should create your own file with fewer formulations and plants to test your code.

Below is the data file for this specific problem:

19 8
43.16 41.54 33.30 42.07 37.45 35.87 37.43 35.59
43.63 48.47 48.23 48.25 46.01 40.38 46.15 48.89
28.47 30.10 29.18 26.09 27.88 24.64 29.67 23.56
15.72 16.76 8.22 25.75 21.30 16.98 25.48 23.15
59.59 59.03 61.28 61.25 56.54 59.88 59.34 62.51
34.37 34.44 26.55 30.31 25.14 25.55 29.97 36.13
66.92 71.49 69.10 74.47 65.64 70.13 72.21 74.40
61.18 55.34 49.03 52.03 50.75 64.40 52.54 57.99
41.04 46.44 38.18 34.99 34.89 44.44 41.11 41.02
77.10 71.46 70.99 77.94 65.98 73.48 74.18 68.78
29.08 22.17 22.26 28.52 31.61 40.93 24.67 28.94
69.59 60.33 67.81 61.03 74.20 65.56 70.50 67.28
56.21 52.60 56.96 57.96 61.85 54.22 46.45 51.64
65.42 55.71 63.84 60.50 65.75 52.16 59.21 55.17
35.72 29.48 31.14 23.83 25.59 26.18 30.30 26.17
50.10 41.84 46.94 45.53 43.27 49.52 48.85 48.10
55.00 62.38 60.05 58.10 59.07 58.21 53.75 58.14
59.51 59.06 58.53 60.40 55.99 64.89 63.56 61.94
67.90 65.61 71.06 67.60 65.86 72.05 67.33 66.23

Solution

#include<stdio.h>
#include<stdlib.h>
FILE *f1;
        float data[50][12];
        char file[20];
void input(int *form, int *plant)
{
        int i,j;      
        printf(\"Enter File Name\ \");
        scanf(\"%s\",file);
        f1= fopen(file,\"r\");
        if(!f1)
        {
                printf(\"File is not exist!\");
                exit(0);
        }
        fscanf(f1,\"%d%d\",form,plant);
        for(i=0;i<*form;i++)
        {
                for(j=0;j<*plant;j++)
                {
                       fscanf(f1,\"%f\",&data[i][j]);
                       if(data[i][j]<15 || data[i][j]>75)
                                printf(\"\ The value of %.2f from plant %d for formulation %d is suspect.\ \",data[i][j],j+1,i+1);
                        printf(\"%.2f \",data[i][j]);
                }
                printf(\"\ \");
        }      
}
void output1D(float *min, float *max, int f)
{
        printf(\"\ 1-dimensional array containing the minimum compressive strengths for each formulation\ \");
        int i;
        for(i=0;i<f;i++)
        {
              printf(\"%.2f\ \",min[i]);
        }
        printf(\"\ 1-dimensional array containing the maximum compressive strengths for each formulation\ \");
        for(i=0;i<f;i++)
        {
              printf(\"%.2f\ \",max[i]);
        }      
}
void minmax(float a[50][12], int f, int p, float min[50], float max[50])
{
        int i,j;
//        float min[f],max[f];
        for(i=0;i<f;i++)
        {
                min[i] = a[i][0];
                max[i] = a[i][0];
                for(j=0;j<p;j++)
                {
                        if(min[i] > a[i][j])
                                min[i]=a[i][j];
                        if(max[i] < a[i][j])
                                max[i]=a[i][j];                      
                }
        }
}
void average_fun(float a[50][12], int f, int p, float min[50], float max[50], float average[50])
{
        int i,j;
        for(i=0;i<f;i++)
        {
                average[i]=0.0;
                for(j=0;j<p;j++)
                {
                        average[i] += a[i][j];
                }
                average[i] = average[i] - min[i] - max[i];
                average[i] = average[i]/(p-2);
//                printf(\"%.2f\",average[i]);
        }
}
void print1d(float *arr, int f, int t)
{
        int i;
        if(t==1)
                printf(\"\ minimum compressive strength for each formulation\ \");
        else if(t==2)
                printf(\"\ maximun compressive strength for each formulation\ \");
        else if(t==3)
                printf(\"\ average compressive strength for each formulation\ \");                      
        for(i=0;i<f; i++)
        {
                printf(\"%.2f\ \",arr[i]);
        }
}
void main()
{
        int i,j,k,l;
        int form, plant;      
        float min[50],max[50],average[50];
        input(&form, &plant);
        minmax(data, form, plant,min,max);
//        output1D(min,max,f);
        average_fun(data, form, plant,min,max,average);
        print1d(min,form,1);
        print1d(max,form,2);      
        print1d(average,form,3);
}

The concrete manufacturer has expanded its study to include more formulations and plants. They have automated the data collection so that the compressive streng
The concrete manufacturer has expanded its study to include more formulations and plants. They have automated the data collection so that the compressive streng
The concrete manufacturer has expanded its study to include more formulations and plants. They have automated the data collection so that the compressive streng

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site