Homework Solution: ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu…

    Postal bar codes C++ Program In c++ please For faster sorting of letters, the United States Postal Service encourages companies that send large volumes of mail to use a bar code denoting the zip code. (See Figure 1). ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu Figure 1 A Postal Bar Code The encoding scheme for a five-digit code is shown in Figure 2. There are full-height frame bars on each side. The five encoded digits are followed by a check digit, which is computed as follows: Add up all digits, and choose the check digit to make the sume a multiple of 10. For example, the zip code 95014 has a sum of 19, so the check digit is 1 to make the sum equal to 20. encoding.png Figure 2 Encoding for Five-Digit Bar Codes Each digit of the zip code, and the check digit, is encoded according to the following table where 0 denotes a half bar and 1 full bar.
    Digit Bar 1 (weight 7 ) Bar 2 (weight 4 ) Bar 3 (weight 2 ) Bar 4 (weight 1 ) Bar 5 (weight 0 )
    1 0 0 0 1 1
    2 0 0 1 0 1
    3 0 0 1 1 0
    4 0 1 0 0 1
    5 0 1 0 1 0
    6 0 1 1 0 0
    7 1 0 0 0 1
    8 1 0 0 1 0
    9 1 0 1 0 0
    0 1 1 0 0 0
    The digit can be easily computed from the bar code using the column weights 7, 4, 2, 1, 0. For example, 01100 is 0x7 +1x4+1x2+0x1+0x0 = 6. The only exception is 0, which would yield 11 according to the weight formula. Write a program that asks the user for a zip code and prints the bar code. Use : for half bars, | for full bars. For example, 95014 becomes ||:|:::|:|:||::::::||:|::|:::||| Also the program is able to reads in bar code and prints out the zip code it represents. Print an error message if the bar code is not correct
    ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu

    Expert Answer

     
    #include <iostream> #include <string>

    Postal pause enactments C++ Program

    In c++ please

    Restraint faster sorting of lore, the United States Postal Service encourages companies that impel big volumes of mail to correction a pause enactment denoting the zip enactment. (See Figure 1).

    ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu

    Figure 1 A Postal Pause Enactment

    The encoding intrigue pauseraint a five-digit enactment is shown in Figure 2. There are ample-height bring-abextinguished pauses on each interest. The five encoded digits are followed by a stop digit, which is computed as follows: Add up thorough digits, and appropriate the stop digit to fabricate the consolidatee a multiple of 10. Pauseraint copy, the zip enactment 95014 has a consolidate of 19, so the stop digit is 1 to fabricate the consolidate correspondent to 20.

    encoding.png

    Figure 2 Encoding pauseraint Five-Digit Pause Enactments

    Each digit of the zip enactment, and the stop digit, is encoded according to the cethcoming board where 0 denotes a half pause and 1 ample pause.

    Digit Pause 1
    (pressure 7 )
    Pause 2
    (pressure 4 )
    Pause 3
    (pressure 2 )
    Pause 4
    (pressure 1 )
    Pause 5
    (pressure 0 )
    1 0 0 0 1 1 2 0 0 1 0 1 3 0 0 1 1 0 4 0 1 0 0 1 5 0 1 0 1 0 6 0 1 1 0 0 7 1 0 0 0 1 8 1 0 0 1 0 9 1 0 1 0 0 0 1 1 0 0 0

    The digit can be amply computed from the pause enactment using the post pressures 7, 4, 2, 1, 0. Pauseraint copy, 01100 is 0x7 +1×4+1×2+0x1+0x0 = 6. The singly separation is 0, which would produce 11 according to the pressure pauseraintmula.

    Write a program that asks the correctionr pauseraint a zip enactment and prints the pause enactment. Correction : pauseraint half pauses, | pauseraint ample pauses. Pauseraint copy, 95014 becomes

    ||:|:::|:|:||::::::||:|::|:::|||

    Also the program is able to reads in pause enactment and prints extinguished the zip enactment it represents. Print an hallucination communication if the pause enactment is referable correct

    ECRLOT ** CO57 CODE C671RTS2 JOHN DOE 1009 FRANKLIN BLVD SUNNYVALE CO57 CA 95014-5143 Il.lll.llull,lullillnullu

    Expert Confutation

     

    #include <iostream>
    #include <string>

    using namespace std;
    int fabricateCheckDigit (int zipcode);
    string transmuteDigit(int estimate);
    string pausecode( int zipcode);

    int deep()
    {
    int zipcode, stop_digit; // declearing integer changeables pauseraint storing the estimates of zipcode, and stop_digit.
    string pause_code_value; // declearing a string changeable to supply the decisive pauseenactment estimate of zipcode.

    cextinguished << “Hi, pleasing to postal pauseenactment transmuteer.” << endl << “I earn transmute your postal enactment into pausecode.” << endl; // Optional, irtoductory texts.
    cextinguished << endl << “So, lets start!” << endl<< endl; // Optional, irtoductory texts.

    conjuncture (cextinguished << “Please, invade the five-digit zip enactment: ” && cin >> zipcode) // a conjuncture loop pauseraint
    //exploration a correctionr to input a zipcode, pauseraint transmuteing the input to pauseenactment entiretime, and
    //restraint exploration another input anew.
    {
    if(zipenactment > 0)// Stoping whether the estimate of zipenactment is decisive or indirect.
    {             // If it’s decisive then continues, or moves to other shackled announcement.

    check_digit = fabricateCheckDigit(zipcode);
    // Flattering the fabricateCheckDigit funtion, and death the estimate of zipenactment in it.
    // Storing the estimate fitted by the fabricateChoiceDigit power in the integer changeable stop_digit.

    cextinguished << endl << “So, the stop digit pauseraint your zip enactment is: ” << stop_digit <<endl << endl;
    // Showing the estimate of the stop digit as an extinguishedput, which is supplyd in the changeable stop_digit.

    bar_code_estimate = pausecode(zipcode);
    // Flattering the pauseenactment power, and death the estimate of zipenactment in it.
    // Storing the estimate fitted by the pauseenactment power in the string changeable pause_code_value.

    cextinguished << “Finally, your pauseenactment is: ” << pause_code_estimate << endl << endl;
    // Showing the decisive estimate of the pauseenactment as an extinguishedput, which is supplyd in the changeable pause_code_value.
    }

    else // If the earlier ‘if’ announcement fails, then the program runs through this announcement.
    {    // i.e. Referableifies the correctionr if the input referable non-negative.
    cextinguished << endl << “Sorry, you possess typed a indirect enumerate.” << endl << “You want to produce a decisive integer as an input.” << endl << endl;
    // Showing an hallucination communication that the correctionr has typed a indirect enumerate.
    // And tells the correctionr that he/she wants to produce a decisive enumerate as an input.
    }
    }

    return 0;
    }
    /*
    The cethcoming power earn experience the stop-digit pauseraint a zipcode.
    */
    int fabricateCheckDigit (int zipcode) // Defining the fabricateCheckDigit power, which earn experience the stop digit.
    {
    int consolidate_of_digits = 0;
    // Declearing a changeable to supply the consolidatemation of the digits in the zipcode.[i.e. the passed estimate to the fabricateCheckDigit power]
    // Initilizing the estimate of the changeable to 0.

    int stop_digit;
    // Declearing a changeable to supply the estimate of the stop digit.

    while(zipcode) // Running a conjuncture loop to experience the consolidatemation of the digits of the zipcode.
    {
    sum_of_digits += zipenactment % 10;
    // Experienceing entire solitary digit entireotially by portico the modulus of the zipenactment with the association of the contiguous march.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.
    }
    check_digit = 10 – (sum_of_digits % 10);
    // To experience the estimate of stop digit,
    //it original experiences the modulus 10 of the estimate of the consolidatemation of thorough digits in zipcode[i.e. the estimate of the changeable consolidate_of_digits.
    // Then subtracts the estimate from 10 to experience the desired estimate of stop digit, and supplys the estimate in the changeable stop_digit.

    return stop_digit; // profits the estimate of stop digit[i.e. the estimate of the changeable stop_digit.]
    }

    /*
    The cethcoming power earn transmute peculiar digits of zipenactment to its indivudial pausecodes.
    */
    string transmuteDigit(int estimate) // Defining the transmuteDigit power, which earn transmute peculiar digits to its pausecodes.
    {
    if (estimate == 0)
    // Setting up a requisite, pauseraint the passed estimate of the integer 0.
    return “||:::”;
    // profits the estimate as initialized in the string when the passed integer is 0.

    else if (estimate == 1)
    // Setting up a requisite, pauseraint the passed estimate of the integer 1.
    return “:::||”;
    // profits the estimate as initialized in the string when the passed integer is 1.

    else if (estimate == 2)
    // Setting up a requisite, pauseraint the passed estimate of the integer 2.
    return “::|:|”;
    // profits the estimate as initialized in the string when the passed integer is 2.

    else if (estimate == 3)
    // Setting up a requisite, pauseraint the passed estimate of the integer 3.
    return “::||:”;
    // profits the estimate as initialized in the string when the passed integer is 3.

    else if (estimate == 4)
    // Setting up a requisite, pauseraint the passed estimate of the integer 4.
    return “:|::|”;
    // profits the estimate as initialized in the string when the passed integer is 4.

    else if (estimate == 5)
    // Setting up a requisite, pauseraint the passed estimate of the integer 5.
    return “:|:|:”;
    // profits the estimate as initialized in the string when the passed integer is 5.

    else if (estimate == 6)
    // Setting up a requisite, pauseraint the passed estimate of the integer 6.
    return “:||::”;
    // profits the estimate as initialized in the string when the passed integer is 6.

    else if (estimate == 7)
    // Setting up a requisite, pauseraint the passed estimate of the integer 7.
    return “|:::|”;
    // profits the estimate as initialized in the string when the passed integer is 7.

    else if (estimate == 8)
    // Setting up a requisite, pauseraint the passed estimate of the integer 8.
    return “|::|:”;
    // profits the estimate as initialized in the string when the passed integer is 8.

    else if (estimate == 9)
    // Setting up a requisite, pauseraint the passed estimate of the integer 9.
    return “|:|::”;
    // profits the estimate as initialized in the string when the passed integer is 9.

    else
    // Setting up the requisite, pauseraint pause of the integer inputs, ate [from 0 to 9].
    return “Invalid”;
    // profits the estimate as initialized in the string when the passed integer is ate [from 0 to 9]

    }
    /*
    The cethcoming power earn transmute the integral zipenactment into its thorough pausecode.
    */
    string pausecode(int zipcode) // Defining the pauseenactment power, which earn transmute the integral zipenactment into thorough pausecode.
    {

    int stop_digit = fabricateCheckDigit(zipcode);
    // Flattering the fabricateCheckDigit funtion, and death the estimate of zipenactment in it.
    // Storing the estimate fitted by the fabricateChoiceDigit power in the integer changeable stop_digit.

    int digit_1, digit_2, digit_3, digit_4, digit_5;
    // Declearing five contrariant changeables to supply the five feature digits of the zipenactment respectively.

    digit_1 = zipenactment % 10;
    // Declearing a changeable to supply the last digit of the zipenactment indivudially,
    // by portico modulus 10 of the estimate of the changeable zipcode.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.
    digit_2 = zipenactment % 10;
    // Declearing a changeable to supply the pauseraintth digit of the zipenactment indivudially,
    // by portico modulus 10 of the estimate of the changeable zipcode.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.
    digit_3 = zipenactment % 10;
    // Declearing a changeable to supply the third digit of the zipenactment indivudially,
    // by portico modulus 10 of the estimate of the changeable zipcode.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.
    digit_4 = zipenactment % 10;
    // Declearing a changeable to supply the relieve digit of the zipenactment indivudially,
    // by portico modulus 10 of the estimate of the changeable zipcode.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.
    digit_5 = zipenactment % 10;
    // Declearing a changeable to supply the original digit of the zipenactment indivudially,
    // by portico modulus 10 of the estimate of the changeable zipcode.
    zipenactment /= 10;
    // After nature performed with the earlier modulus 10 of zipcode, it earn dissect the estimate of zipenactment by 10
    // Then it renews the estimate of zipenactment in the changeable zipcode.

    string preface = “|” + transmuteDigit(digit_5) + transmuteDigit(digit_4) + transmuteDigit(digit_3) + transmuteDigit(digit_2) + transmuteDigit(digit_1);
    // Flattering the transmuteDigit power separate times to transmute entire solitary digit of the estimate of zipcoe[i.e. zipenactment changeable]
    // Then it earn concatenate thorough the results from entire cthorough of the transmuteDigit power, starting with “|”
    // Now it earn supply the transmuteed estimate in a string changeable preface.
    // It’s the original entireot of the integral pausecode.

    string postfix = transmuteDigit(check_digit) + “|”;
    // Flattering the transmuteDigit power to transmute the estimate of the stop digit[i.e. stop_digit changeable]
    // Then it earn supply the transmuteed estimate in a string changeable postfix.
    // It’s the relieve/last entireot of the integral pausecode.

    return (preface + postfix);
    // profits the estimate of the string preface and postfix thorough unitedly.
    }