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

A data file \"parttolerance.dat\" stores on one line, a part number, and the min

ID: 3826169 • Letter: A

Question

A data file "parttolerance.dat" stores on one line, a part number, and the minimum and maximum values for the valid range that the part could weigh Write a script "parttol" that will read these values from the file, prompt the user for a weight, and print whether or not that weight is within range. For example, IF the file stores the following: >> type part tolerance .dat 123 44.205 44.287 Here might be examples of executing the script: >> parttol Enter the part weight: 44.33 The part 123 is not in range >> parttol Enter the part weight: 44.25 The part 123 is within range

Explanation / Answer

%Matlab script as per requirements

%following command prints the content of parttolerance.dat file
%type parttolerance.dat

fileID = fopen('parttolerance.dat','r');
formatSpec = '%f';
A = fscanf(fileID,formatSpec)
%print A
cg=A(1) %contains part number
low=A(2)%contains lower limit
high=A(3) %contains upper limit
weight=input("Enter the part weight ")
if (weight<high && weight>=low)
fprintf("The part is %d within range ",cg)
else
fprintf("The part %d is not in range ",cg)
end

Output :

Enter the part weight                                                                                                                                     

44.25                                                                                                                                                     

weight =  44.250                                                                                                                                          

The part is 123 within range