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

I need help with this Assignment 10 in Simple C on Geany. It is essentially an i

ID: 3703673 • Letter: I

Question

I need help with this Assignment 10 in Simple C on Geany. It is essentially an improvement from ter nter 3 PgDn End Del Ins ASSIGNMENT 10: Data validation Name: Station # Programming problem: This program is simply an improvement over Assignment 9. This better version will also consider whether or not the size read in from the file is VALID. The program will keep track of total number, good, bad, & valid diameters. The program will ONLY STOP once the end of the file is found. Like #8, a ball bearing is classified as faulty if its diameter is less than 1.96 mm or greater than 2.04 mm. The program will also keep track of the average bearing diameter. Program summary 1. 2. Reads data from a file until the end of the file is found. Reports the size and number of the bearing read in for each bearing value in the file. 3. Reports the number of valid, invalid, good, bad, and total bearings after reading in each bearing size (e.g. within the loop). ALSO reports the average diameter of the VALID bearings examined. 4. After the end of the file is found (e.g. loop stops/stops reading in sizes): Reports the total number of bearings, the number of valid bearings, the number of invalid bearings, the number of good bearings, the number of bad bearings, and the average bearing diameter (considering only valid bearings) for each iteration. a. b. After reading in all of the bearings the program reports: i. Total number of bearings read. ii. Total number of valid and invalid bearings read. i. Percentage of good ball bearings considering valid sizes only. iv. Percentage of bad ball bearings considering valid sizes only v. Average ball bearing diameter for valid sizes only 5. Note: the 2.0 mm+/-0.05 mm is NOT the range used for VALIDATION... that is the test for GOOD versus BAD... a larger range will be used for testing validation The text file will contain a mixture of good (within tolerance), bad (outside of tolerance), AND INV ALID sizes (see your answer to Q1). Recall however that the program will only quit when the end of 6. the file is found.

Explanation / Answer

VALBEAR.C


#include <stdio.h>

int main(void)
{
   float sum_size_goodBearings=0;
   float average_size_goodBearings = 0;
   int totalBearings=0;
   int total_goodBearings=0;
   int total_badBearings=0;
   float percentage_goodBearings=0;
   float percentage_badBearings=0;


   FILE *fp;
   float currentBearingValue;

   fp = fopen("beardata.txt", "r");
   if(fp==NULL)
   {
       printf("Error opening file");
       exit(1);
   }

   printf(" Reading bearings data from beardata.txt file");
   printf(" --------------------------------------------");

   fscanf(fp,"%f", &currentBearingValue);
   while(! feof(fp))
   {
       printf(" %f", currentBearingValue);

       totalBearings++;
       if (currentBearingValue < 1.96 || currentBearingValue>2.04)
       {
           printf(" is BAD");
           total_badBearings++;
       }
       else
       {
           printf(" is GOOD");
           total_goodBearings++;
           sum_size_goodBearings = sum_size_goodBearings + currentBearingValue;
       }

       fscanf(fp,"%f", &currentBearingValue);
   }

   average_size_goodBearings = sum_size_goodBearings / total_goodBearings;
   percentage_goodBearings = ((float)total_goodBearings / (float)totalBearings) * 100;
   percentage_badBearings = ((float)total_badBearings / (float)totalBearings) * 100;


   fclose(fp);


   printf(" Average size of good bearings is : %f", average_size_goodBearings);
   printf(" Total number of Bearings read from file: %d",totalBearings);
   printf(" Total number of good bearings is : %d", total_goodBearings);
   printf(" Total number of bad bearings is : %d",total_badBearings);
   printf(" Percentage of good bearings is %f", percentage_goodBearings);
   printf(" Percentage of bad bearings is %f",percentage_badBearings);

   return 0;
}

BEARDATA.TXT

1.97
1.96
1.95
2.545
4.56
3.4
1.99
1.99
1.99

OUTPUT


Reading bearings data from beardata.txt file
--------------------------------------------
1.970000 is GOOD
1.960000 is GOOD
1.950000 is BAD
2.545000 is BAD
4.560000 is BAD
3.400000 is BAD
1.990000 is GOOD
1.990000 is GOOD
1.990000 is GOOD

Average size of good bearings is : 1.980000

Total number of Bearings read from file: 9

Total number of good bearings is : 5

Total number of bad bearings is : 4

Percentage of good bearings is 55.555557

Percentage of bad bearings is 44.444443

ASSUMPTION

It is assumed that all bearings within the accepted range of 1.96 to 2.04 is VALID and GOOD. It is assumed that all data in text file is in float format.

Your code or the question did not specify which are invalid cases. It seems like if the text is not in numeric format, it is considered as INVALID but I have not coded this assumption due to time constraint. You can add the code as necessary

NOTES

You had coded average calculations within the loop. Average can be determined once all totals are determined. Hence totals are calculated within the loop and Average is finally calculated at the end outside the loop. I have rewritten the program. Format it as necessary.

If you know exactly from your previous assignment which bearing readings are considered invalid or valid, then you can add that code within the loop as relevant and show its total outside the loop