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

COBOL. Interactive VIN Validation Program VINs or Vehicle Identification Numbers

ID: 3836834 • Letter: C

Question

COBOL. Interactive VIN Validation Program
VINs or Vehicle Identification Numbers are important identifiers. For example, they may enable police to determine the owner of a recovered stolen vehicle. However, the VIN must be a valid one. Write an interactive program that will check a VIN enteredfrom the keyboard and display whether it is valid. The program must indicate why the VIN is invalid and must continue to validate VINs until the user indicates that there are no more VINs to validate.
The characteristics of each VIN record are as follows:
1. 17 characters long.
2. The first character must be either 1, 5, 7, F, J, T, X, or Z.
3. The tenth character must be a digit or a letter other than K, M, R, V, or Z. 4. The last six characters must be numeric.

Explanation / Answer

Answer: See the code below:

----------------------------------------

IDENTIFICATION DIVISION.
PROGRAM-ID. VALIDATE-VIN.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-VIN PIC X(17).
77 WS-VIN-LEN PIC 9(2) VALUE 0.
77 WS-VIN-FIRST-CHAR PIC X(1).
77 WS-VIN-TENTH-CHAR PIC X(1).
77 WS-VIN-LAST-SIX-CHAR PIC X(6).
PROCEDURE DIVISION.
FIRST-PARA.
PERFORM
    DISPLAY 'This program validates VIN.'.
    DISPLAY 'Enter VIN to validate:'.
    ACCEPT WS-VIN FROM CONSOLE.
    DISPLAY "Entered VIN:"WS-VIN.
    INSPECT WS-VIN TALLYING WS-VIN-LEN FOR ALL CHARACTERS.
    DISPLAY "VIN LENGTH: "WS-VIN-LEN.
  
    IF WS-VIN-LEN = 17 THEN
        MOVE WS-VIN(1:1) TO WS-VIN-FIRST-CHAR
        IF WS-VIN-FIRST-CHAR = '1' OR WS-VIN-FIRST-CHAR = '5' OR WS-VIN-FIRST-CHAR = '7' OR WS-VIN-FIRST-CHAR = 'F' OR WS-VIN-FIRST-CHAR = 'J' OR WS-VIN-FIRST-CHAR = 'T' OR WS-VIN-FIRST-CHAR = 'X' OR WS-VIN-FIRST-CHAR = 'Z'
            MOVE WS-VIN(10:1) TO WS-VIN-TENTH-CHAR
            IF WS-VIN-TENTH-CHAR NOT = 'K' OR WS-VIN-TENTH-CHAR NOT = 'M' OR WS-VIN-TENTH-CHAR NOT = 'R' OR WS-VIN-TENTH-CHAR NOT = 'V' OR WS-VIN-TENTH-CHAR NOT = 'Z'
                MOVE WS-VIN(12:6) TO WS-VIN-LAST-SIX-CHAR
                IF function TEST-NUMVAL(WS-VIN-LAST-SIX-CHAR) equal zero then
                    DISPLAY 'VIN OK'
                ELSE
                    DISPLAY 'Last six character not numeric.'
                END-IF
            ELSE
                DISPLAY 'Wrong tenth character'
            END-IF
        ELSE
            DISPLAY 'Wrong first character'
        END-IF
   ELSE
       DISPLAY 'Wrong length of VIN'
   END-IF.
UNTIL WS-VIN = 'EXIT'.
STOP RUN.

---------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote