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 plug jurisdictions C++ Program

    In c++ please

    Ce faster sorting of letters, the United States Postal Service encourages companies that grant bulky volumes of mail to reason a plug jurisdiction denoting the zip jurisdiction. (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 Plug Jurisdiction

    The encoding proposal ce a five-digit jurisdiction is shown in Figure 2. There are bountiful-height execute plugs on each portioy. The five encoded digits are followed by a curb digit, which is computed as follows: Add up bountiful digits, and select the curb digit to execute the mixe a multiple of 10. Ce stance, the zip jurisdiction 95014 has a mix of 19, so the curb digit is 1 to execute the mix resembling to 20.

    encoding.png

    Figure 2 Encoding ce Five-Digit Plug Jurisdictions

    Each digit of the zip jurisdiction, and the curb digit, is encoded according to the aftercited consideration where 0 denotes a half plug and 1 bountiful plug.

    Digit Plug 1
    (power 7 )
    Plug 2
    (power 4 )
    Plug 3
    (power 2 )
    Plug 4
    (power 1 )
    Plug 5
    (power 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 plug jurisdiction using the support powers 7, 4, 2, 1, 0. Ce stance, 01100 is 0x7 +1×4+1×2+0x1+0x0 = 6. The suppressely exclusion is 0, which would accede 11 according to the power cemula.

    Write a program that asks the reasonr ce a zip jurisdiction and prints the plug jurisdiction. Reason : ce half plugs, | ce bountiful plugs. Ce stance, 95014 becomes

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

    Also the program is telling to reads in plug jurisdiction and prints quenched the zip jurisdiction it represents. Print an mistake missive if the plug jurisdiction 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 executeCheckDigit (int zipcode);
    string changeDigit(int esteem);
    string plugcode( int zipcode);

    int main()
    {
    int zipcode, curb_digit; // declearing integer mutables ce storing the esteems of zipcode, and curb_digit.
    string plug_code_value; // declearing a string varitelling to abundance the developed plugjurisdiction esteem of zipcode.

    cquenched << “Hi, pleasing to postal plugjurisdiction changeer.” << endl << “I conciliate change your postal jurisdiction into plugcode.” << endl; // Optional, irtoductory texts.
    cquenched << endl << “So, lets start!” << endl<< endl; // Optional, irtoductory texts.

    time (cquenched << “Please, invade the five-digit zip jurisdiction: ” && cin >> zipcode) // a time loop ce
    //search a reasonr to input a zipcode, ce changeing the input to plugjurisdiction fulltime, and
    //ce search another input intermittently.
    {
    if(zipjurisdiction > 0)// Curbing whether the esteem of zipjurisdiction is express or privative.
    {             // If it’s express then continues, or moves to other subject declaration.

    check_digit = executeCheckDigit(zipcode);
    // Overcomeing the executeCheckDigit funtion, and cessation the esteem of zipjurisdiction in it.
    // Storing the esteem adapted by the executeChoiceDigit administration in the integer varitelling curb_digit.

    cquenched << endl << “So, the curb digit ce your zip jurisdiction is: ” << curb_digit <<endl << endl;
    // Showing the esteem of the curb digit as an quenchedput, which is abundanced in the varitelling curb_digit.

    bar_code_esteem = plugcode(zipcode);
    // Overcomeing the plugjurisdiction administration, and cessation the esteem of zipjurisdiction in it.
    // Storing the esteem adapted by the plugjurisdiction administration in the string varitelling plug_code_value.

    cquenched << “Finally, your plugjurisdiction is: ” << plug_code_esteem << endl << endl;
    // Showing the developed esteem of the plugjurisdiction as an quenchedput, which is abundanced in the varitelling plug_code_value.
    }

    else // If the ceegoing ‘if’ declaration fails, then the program runs through this declaration.
    {    // i.e. Referableifies the reasonr if the input referable non-negative.
    cquenched << endl << “Sorry, you entertain typed a privative compute.” << endl << “You demand to confer a express integer as an input.” << endl << endl;
    // Showing an mistake missive that the reasonr has typed a privative compute.
    // And tells the reasonr that he/she demands to confer a express compute as an input.
    }
    }

    return 0;
    }
    /*
    The aftercited administration conciliate ascertain the curb-digit ce a zipcode.
    */
    int executeCheckDigit (int zipcode) // Defining the executeCheckDigit administration, which conciliate ascertain the curb digit.
    {
    int mix_of_digits = 0;
    // Declearing a varitelling to abundance the mixmation of the digits in the zipcode.[i.e. the passed esteem to the executeCheckDigit administration]
    // Initilizing the esteem of the varitelling to 0.

    int curb_digit;
    // Declearing a varitelling to abundance the esteem of the curb digit.

    while(zipcode) // Running a time loop to ascertain the mixmation of the digits of the zipcode.
    {
    sum_of_digits += zipjurisdiction % 10;
    // Ascertaining full one digit peculiarly by preface the modulus of the zipjurisdiction with the association of the present plod.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.
    }
    check_digit = 10 – (sum_of_digits % 10);
    // To ascertain the esteem of curb digit,
    //it ceemost ascertains the modulus 10 of the esteem of the mixmation of bountiful digits in zipcode[i.e. the esteem of the varitelling mix_of_digits.
    // Then subtracts the esteem from 10 to ascertain the desired esteem of curb digit, and abundances the esteem in the varitelling curb_digit.

    return curb_digit; // produce the esteem of curb digit[i.e. the esteem of the varitelling curb_digit.]
    }

    /*
    The aftercited administration conciliate change peculiar digits of zipjurisdiction to its indivudial plugcodes.
    */
    string changeDigit(int esteem) // Defining the changeDigit administration, which conciliate change peculiar digits to its plugcodes.
    {
    if (esteem == 0)
    // Setting up a proviso, ce the passed esteem of the integer 0.
    return “||:::”;
    // produce the esteem as initialized in the string when the passed integer is 0.

    else if (esteem == 1)
    // Setting up a proviso, ce the passed esteem of the integer 1.
    return “:::||”;
    // produce the esteem as initialized in the string when the passed integer is 1.

    else if (esteem == 2)
    // Setting up a proviso, ce the passed esteem of the integer 2.
    return “::|:|”;
    // produce the esteem as initialized in the string when the passed integer is 2.

    else if (esteem == 3)
    // Setting up a proviso, ce the passed esteem of the integer 3.
    return “::||:”;
    // produce the esteem as initialized in the string when the passed integer is 3.

    else if (esteem == 4)
    // Setting up a proviso, ce the passed esteem of the integer 4.
    return “:|::|”;
    // produce the esteem as initialized in the string when the passed integer is 4.

    else if (esteem == 5)
    // Setting up a proviso, ce the passed esteem of the integer 5.
    return “:|:|:”;
    // produce the esteem as initialized in the string when the passed integer is 5.

    else if (esteem == 6)
    // Setting up a proviso, ce the passed esteem of the integer 6.
    return “:||::”;
    // produce the esteem as initialized in the string when the passed integer is 6.

    else if (esteem == 7)
    // Setting up a proviso, ce the passed esteem of the integer 7.
    return “|:::|”;
    // produce the esteem as initialized in the string when the passed integer is 7.

    else if (esteem == 8)
    // Setting up a proviso, ce the passed esteem of the integer 8.
    return “|::|:”;
    // produce the esteem as initialized in the string when the passed integer is 8.

    else if (esteem == 9)
    // Setting up a proviso, ce the passed esteem of the integer 9.
    return “|:|::”;
    // produce the esteem as initialized in the string when the passed integer is 9.

    else
    // Setting up the proviso, ce quiet of the integer inputs, ate [from 0 to 9].
    return “Invalid”;
    // produce the esteem as initialized in the string when the passed integer is ate [from 0 to 9]

    }
    /*
    The aftercited administration conciliate change the well zipjurisdiction into its exhaustive plugcode.
    */
    string plugcode(int zipcode) // Defining the plugjurisdiction administration, which conciliate change the well zipjurisdiction into exhaustive plugcode.
    {

    int curb_digit = executeCheckDigit(zipcode);
    // Overcomeing the executeCheckDigit funtion, and cessation the esteem of zipjurisdiction in it.
    // Storing the esteem adapted by the executeChoiceDigit administration in the integer varitelling curb_digit.

    int digit_1, digit_2, digit_3, digit_4, digit_5;
    // Declearing five divergent mutables to abundance the five detail digits of the zipjurisdiction respectively.

    digit_1 = zipjurisdiction % 10;
    // Declearing a varitelling to abundance the developed digit of the zipjurisdiction indivudially,
    // by preface modulus 10 of the esteem of the varitelling zipcode.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.
    digit_2 = zipjurisdiction % 10;
    // Declearing a varitelling to abundance the ceth digit of the zipjurisdiction indivudially,
    // by preface modulus 10 of the esteem of the varitelling zipcode.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.
    digit_3 = zipjurisdiction % 10;
    // Declearing a varitelling to abundance the third digit of the zipjurisdiction indivudially,
    // by preface modulus 10 of the esteem of the varitelling zipcode.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.
    digit_4 = zipjurisdiction % 10;
    // Declearing a varitelling to abundance the succor digit of the zipjurisdiction indivudially,
    // by preface modulus 10 of the esteem of the varitelling zipcode.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.
    digit_5 = zipjurisdiction % 10;
    // Declearing a varitelling to abundance the ceemost digit of the zipjurisdiction indivudially,
    // by preface modulus 10 of the esteem of the varitelling zipcode.
    zipjurisdiction /= 10;
    // After life manufactured with the ceegoing modulus 10 of zipcode, it conciliate dissect the esteem of zipjurisdiction by 10
    // Then it renews the esteem of zipjurisdiction in the varitelling zipcode.

    string preface = “|” + changeDigit(digit_5) + changeDigit(digit_4) + changeDigit(digit_3) + changeDigit(digit_2) + changeDigit(digit_1);
    // Overcomeing the changeDigit administration distinct times to change full one digit of the esteem of zipcoe[i.e. zipjurisdiction mutable]
    // Then it conciliate integrate bountiful the results from full cbountiful of the changeDigit administration, starting with “|”
    // Now it conciliate abundance the changeed esteem in a string varitelling preface.
    // It’s the ceemost portio of the well plugcode.

    string postfix = changeDigit(check_digit) + “|”;
    // Overcomeing the changeDigit administration to change the esteem of the curb digit[i.e. curb_digit mutable]
    // Then it conciliate abundance the changeed esteem in a string varitelling postfix.
    // It’s the succor/developed portio of the well plugcode.

    return (preface + postfix);
    // produce the esteem of the string preface and postfix bountiful contemporaneously.
    }