Ask 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 parttolerance. dat123 44.205 44.287Here might be examples of executing the script:>> parttolEnter the part weight: 44.33The part 123 is not in range>> parttolEnter the part weight: 44.25The part 123 is within range

+2
Answers (1)
  1. 23 April, 09:51
    0
    First, create the parttolerance. dat file with the line in the question. This can easily be done by using the echo command from the command line:

    echo 123 44.205 44.287 >> parttolerance. dat

    Then write a simple script file that prompts the user for the weight and then compares that input to the values within the file created above. If the value of the weight is within the range, then print the value is within range. Otherwise print it is not within range.

    Explanation:

    / / create the parttolerance. dat file

    echo 123 44.205 44.287 >> parttolerance. dat

    Shell script

    #!/bin/bash echo

    "Enter the part weight: "

    read input_weight

    IFS=' ' while IFS=' '

    read - r col1 col2 col3 do

    part_number="$col1"

    file_weight_lower="$col2"

    file_weight_upper="$col3"

    done
    if (($ (bc << = $file_weight_lower && $input_weight 0)); then

    echo "The part $part_number is within range"

    else

    echo "The part $part_number is not in range"

    fi

    run script:

    ./parttol. sh
Know the Answer?
Not Sure About the Answer?
Find an answer to your 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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers