Question

In: Physics

Part I The input to the program will be a text file containing the information for...

Part I 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 gap 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 input values will be processed using the methods 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”)  

Part II The second stage extends the Stage 1 analysis. In this stage the program will suggest various combinations of part dimensions and tolerances to meet the gap specifications. The fixed dimension parts are not able to have their dimensions or tolerances adjusted. Take the required adjustment to all the variable parts and apply this adjustment to each part equally as a percentage of the total part dimension. Round dimensions to the nearest thousandth. Do the same application to adjust the gaps of all parts to have the gap fully use the available tolerance. Example Input: 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 Example Output: Recommended Adjustments to meeting GAP,0.000,0.80: PART,1.990,-1,0.020,V PART,0.970,-1,0.010,V PART,3.000,+1,0.010,F Math used to get to the result Variable parts should add to (3 – 0.04) = 2.96 Variable parts actually add to (2 + 0.975) = 2.975 All variable parts must be adjusted to 2.96/2.975 = 99.496% of the original value Variable tolerance should add to (0.04 – 0.01) = 0.03 Variable tolerance actually add to (0.05 + 0.025) = 0.075 All variable parts’ tolerance must be adjusted to 0.3/0.073 = 40% of the original value

Part III The third stage involves a statistical analysis called Monte Carlo simulation. Basically each of the dimensions is varied randomly and the gap is calculated. This random calculation is repeated hundreds or thousands of times. For each iteration, the individual gap value is calculated and stored in an array and in a file. The array of values will be used to compute the mean and standard deviation of the gap. The file will be opened using a spreadsheet program to graph a histogram, calculate an average, and calculate the standard deviation, which should match the result from your program. These values will then be used to estimate the number of rejected assemblies during production. It is reasonable to assume that the tolerance for a part is 3 standard deviations (99.73% of parts will fall within the tolerance). So for any part, we can generate random realistic values by taking the nominal value and adding/subtracting a random number, which represents variations due to the tolerance. To do this, we will need to generate a specific type of random numbers. The standard random number function in most programming language (rand() in C included) has a uniform distribution. This means that if we are finding random numbers from 0.0 to 1.0, the probability of getting 0.5 is the same as getting 0.1. This is not realistic for our application, since it will be more likely that we have our dimensions change by 0.1 than it is 0.5. For this reason, we need to modify the numbers from the rand() function so that they have a Gaussian (Normal) Distribution, which is sometimes referred to as the “bell curve”. This can be accomplished by using the Box-Muller Transformation. Although it sounds complicated, this transformation can be easily done and applied to generate a random dimension with the code given. Summary of Part 3: Apply the random_dimension() function below to get an output of a random_value of each part that will follow the explanation above. This will create a statistically likely value for each dimension given that you can then use to rerun the “actual mean gap” calculation from Part 1 1000 times. For each calculation, have the program store the value as a line in a text file (.csv extension.) You’ll be able to open this file up using Excel as a .csv file. In Excel, graph a histogram, calculate the average gap of all assemblies (of parts), and the standard deviation of the gap of all assemblies. void random_dimension(double nominal, double tolerance, double *random_value){ double r1, r2, r12; double sigma = tolerance / 3; do{ r1 = (double)( rand() % 10001 ) / 10000; }while(r1==0); r2 = (double)( rand() % 10001 ) / 10000; r12 = sqrt(-2*log(r1))*cos(2*M_PI*r2); *random_value = nominal + sigma * r12; }

Solutions

Expert Solution

/** C code for tolerance analysis **/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define BUFFER_SIZE 1024
#define ARRAYSIZE 100
// returns the number elements stored in arrays
int input(float nom[],float tollerance[],int SIGNS[],char V_F[],float p_Spec_Minnimum,float p_Spec_Maximum)
{
int status = 0, i,c;
FILE *FTIN;
FTIN = fopen ("filename", "r");

if (FTIN == NULL){ //file empty/broken error
printf("ERROR\n");
return (-1);
}
/******/
else{
for (i=0; status != EOF && i < 100; ){ //reads until EoF, even though some guy on stackoverflow taught me it's bad
status = fscanf(FTIN,"PART,%f,%d,%f,%c\n", &nom[i], &SIGNS[i], &tollerance[i], &V_F[i]); //scans for a part
if(status == 4)
{
i++;
}
status = fscanf(FTIN, "GAP,%f,%f\n", p_Spec_Minnimum, p_Spec_Maximum); //scans for a gap
//printf("Reading Info Into Arrays\n");
}
fclose(FTIN);
return i;
}
}
// output arrays in special format
void output(int size, float nom[],float tollerance[],int SIGNS[],char V_F[],float Spec_Minnimum,float Spec_Maximum)
{
int i;
for (i=0; i < size; i++)
{
printf("PART,%f,%d,%f,%c\n", nom[i], SIGNS[i], tollerance[i], V_F[i]);
}
printf("GAP,%f,%f\n", Spec_Minnimum, Spec_Maximum);
}


float toleracningPt1(int size, float nom[],float tollerance[],int SIGNS[],char V_F[],float Spec_Minnimum,float Spec_Maximum)
{
int x;
float Act_Gap, Act_Tollerance, Maximum_Gap = 0.0, Minnimum_Gap = 0.0;
for ( x=0, Act_Gap = 0; x<size; x++){ //does tolerance math
Act_Gap = Act_Gap + (nom[x]*SIGNS[x]);
}
for ( x=0, Act_Tollerance = 0; x<size; x++){
Act_Tollerance = Act_Tollerance + (tollerance[x]);
}
for (x= 0, Maximum_Gap = 0; x<size; x++){
Maximum_Gap = (nom[x]*SIGNS[x]+tollerance[x])+Maximum_Gap;
Minnimum_Gap = (nom[x]*SIGNS[x]-tollerance[x])+Minnimum_Gap;
}

printf("Actual Gap Mean: %.3f\"\n", Act_Gap); //printing
printf("Actual Gap Tolerance: %.3f\"\n", Act_Tollerance);
if (Maximum_Gap > Spec_Maximum){
printf("The maximum gap (%.3f\") is (Greater) than specified (%.3f\")\n", Maximum_Gap, Spec_Maximum);
}
if (Maximum_Gap < Spec_Maximum){
printf("The maximum gap (%.3f\") is (Less) than specified (%.3f\")\n", Maximum_Gap, Spec_Maximum);
}
if (Minnimum_Gap > Spec_Minnimum){
printf("The minimum gap (%.3f\") is (Greater) than specified (%.3f\")\n", Minnimum_Gap, Spec_Minnimum);
}
if (Minnimum_Gap < Spec_Minnimum){
printf("The minimum gap (%.3f\") is (Less) than specified (%.3f\")\n", Minnimum_Gap, Spec_Minnimum);
}
}

int main(void){
/**Decs**/
float nom[100], tollerance[100];
int SIGNS[100];
char V_F[100];
//int status, i, x;
float Act_Gap, Act_Tollerance, Spec_Minnimum, Spec_Maximum;
/**custom functions**/
int size = 0;
size = input( nom, tollerance, SIGNS, V_F, &Spec_Minnimum, &Spec_Maximum);
output( size, nom, tollerance, SIGNS, V_F, Spec_Minnimum, Spec_Maximum);
toleracningPt1(size, nom, tollerance, SIGNS, V_F, Spec_Minnimum, Spec_Maximum);
}


Related Solutions

Write a program that reads a file called document.txt which is a text file containing an...
Write a program that reads a file called document.txt which is a text file containing an excerpt from a novel. Your program should print out every word in the file that contains a capital letter on a new line to the stdout. For example: assuming document.txt contains the text C++
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
Write a C program to find out the number of words in an input text file...
Write a C program to find out the number of words in an input text file (in.txt). Also, make a copy of the input file. Solve in C programming.
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
Write a C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
I just finished this program where the program reads a text file of full names ,...
I just finished this program where the program reads a text file of full names , first and last name, and a zip code. It reads the items then stores the first name and last name and zipcodes as an objects and prints the items.   However, when i use my text file i get this error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 " I notice this issue only happens when the names are...
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
Allow the main process to generate a text file containing the text of this assignment. The...
Allow the main process to generate a text file containing the text of this assignment. The main process will then create two other processes and pass to them the name of the file and two codes (code1 and code2) using a pipe() system call. The codes are two different alphabetic letters such as “a” and “k”. The child processes should search the file for the character in the interval received, compute their frequencies and return them through a separate pipe...
Write a Python program that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT