Load a tolerance table from a file from examples below. This will load a toleran
ID: 3682372 • Letter: L
Question
Load a tolerance table from a file from examples below. This will load a tolerance table and stimate gap sizes and tolerances.
The input to the program will be a text file containing the information for a tolerance table. An example follows using the values from the first lecture on tolerance analysis. These values will be stored in a text file. The data is comma delimited, which means that each data field is separated by a comma. If the first word is ‘PART’ the following values are the nominal size, +/- impact, tolerance, and fixed/variable. If the first word is ‘GAP’ the following values are the minimum and maximum sizes. (Note: assume all units are inches.)
PART,2.000,-1,0.050,V
PART,0.975,-1,0.025,V
PART,3.000,+1,0.010,F
GAP,0.000,0.080
These values will be processed using the method taught in class. A sample output for the first stage is given.
Actual Gap Mean: 0.025”
Actual Gap Tolerance: 0.085”
The Maximum Gap (0.110”) is (Greater) than specified (0.080”)
The Minimum Gap (-0.060”) is (Less) than the specified (0.000”)
Files given:
input.txt:
input2.txt:
input3:
input4:
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
#define max_lines 10
#define file_size 25
int show_file(void);
void analysis(void);
void show(void);
void adjust(void);
void scaling(void);
void monte_carlo(void);
FILE *p1;
int i, j;
int impact[10], i, num;
float nominal[10];
float tol[10];
float max, gap_minimum, n, tol, AGM, AGT, gap_maximum, gap;
char gap1, gap2, gap3, gap4, FoV;
int main()
{
char menu;
int quit=0;
while(quit==0)
{
printf(" action list ");
printf("-1=load -2=simple analysis -3=adjustments: individual parts -4=adjustments: scaling factor -5=monte carlo -0=quit:
");
fflush(stdin);
scanf("%c", &menu);
switch(menu)
{
case '0':
quit=1;
printf("Exited the program!!. ");
break;
case '1':
quit=show_file();
break;
case '2':
analysis();
break;
case '3':
adjust();
break;
case '4':
scaling();
break;
case '5':
monte_carlo();
break;
default:
printf("error");
fflush(stdin);
printf(" Please press ");
fgetc(stdin);
}
return 0;
}
void show()
{
printf("this program provide tol and gap sizes ");
}
int show_file(void)
{
char fileName[100];
printf("Please enter file name ");
scanf("%s", fileName);
p1 = fopen(fileName,"r");
for (i=0; i<=max_lines; i++){
fscanf(p1, "%c%c%c%c,",&gap1,&gap2,&gap3,&gap4);
if (gap1 == 'P'){
fscanf(p1, "%f,%d,%f,%c ",&n, &i,&tol, &FoV);
num ++;
nominal[num] = n;
impact[num] = i;
tol[num] = tol;
printf("Part: %.3f,%.3d,%.3f,%c ",n, i, tol, FoV);
}
else if (gap1 == 'G'){
fscanf(p1, "%f,%f, ",&gap_minimum, &max);
printf("Gap: %.3f,%.3f ",gap_minimum,max);
break;
}
}
fclose(p1);
return 0;
}
void analysis(void){
for (i=1; i<=num; i++){
AGM = AGM + nominal[i]*impact[i];
AGT = AGT + tol[i];
}
gap_maximum = AGM + AGT;
printf("ActualGapMean = %.3f" ",AGM);
gap = AGM - AGT;
printf("ActualGaptol = %.3f" ",AGT);
if (gap_maximum < max)
{
printf("The max. gap %.3f" is . %.3f" ",gap_maximum, max);
}
else if (gap_maximum > max){
printf("The max. gap %.3f" is . %.3f" ", gap_maximum, max);
}
else if (gap_maximum == max){
printf("The max. gap %.3f" is .%.3f" ", gap_maximum, max);
}
if (gap < gap_minimum)
{
printf("The min. gap %.3f" is %.3f" ",gap, gap_minimum);
}
else if (gap > gap_minimum){
printf("The min. gap %.3f" is %.3f" ", gap, gap_minimum);
}
else if (gap == gap_minimum){
printf("The min. gap %.3f" is%.3f" ", gap, gap_minimum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.